You are here

strange behavior in the context with the choice of the language

6 posts / 0 new
Last post
tapsklaps
Offline
Last seen: 5 years 6 months ago
Developer
Joined: 2010-10-17 08:11
strange behavior in the context with the choice of the language

I analyzed in connection with the development of the portable version of the program Drago the switching of the language. Here I focused specifically on the case of the standalone version of the program. For better understanding I would first explain a few facts.

In the subfolder settings of the folder DefaultData I have inserted the file Drago.ini. In the section "Options" I have determined for the key "Language" the value "Hu" (Hungarian).

Subsequently briefly the content of the file DragoPortable.ini:

[Launch]
ProgramExecutable=Drago\Drago.exe
SinglePortableAppInstance=true
WaitForOtherInstances=false
DirectoryMoveOK=yes

[Activate]
Registry=true

[RegistryKeys]
Cygwin=HKLM\SOFTWARE\Cygwin
Installations=HKLM\SOFTWARE\Cygwin\Installations
Program_Options=HKLM\SOFTWARE\Cygwin\Program Options

[Language]
Base=%PortableApps.comLanguageCode%
Default=en 

[LanguageStrings]
ar-sa=Ar
zh-cn=Cn
zh-tw=Ct
cs=Cz
de=De
en=En
es=Es
fr=Fr
ja=Jp
ko=Kr
hu=Hu
pl=Pl
pt-br=Br
ru=Ru
sk=Sk
tr=Tr
vi=Vn

;[LanguageFile]
;Type=INI
;File=%PAL:DataDir%\Settings\Drago.ini
;Section=Options
;Key=Language

[FilesMove]
settings\Drago.ini=%PAL:AppDir%\Drago
settings\engines.config=%PAL:AppDir%\Drago

[FileWrite1]
Type=Replace
File=%PAL:DataDir%\settings\Drago.ini
Find=THISSTRINGWILLBEREPLACEDBYAPPDIR
Replace=%PAL:AppDir%

[FileWrite2]
Type=INI
File=%PAL:DataDir%\settings\drago.ini
Section=Options
Key=Language
Value=%PAL:LanguageCustom%

I want to note, that I have disabled for this test the section [LanguageFile].

After these introductory remarks, I would now like to come to my problems.

  1. Question #1

    Due to the above conditions after the first run of the program the Hungarian language should be selected. Instead, the program appears, however, in the English language. But why?

  2. Question #2

    During the first start of the program I then changed the language from English to German.
    After the close of the program I looked at the file Drago.ini in the folder Data\settings. In the section "Options" I found for the key "Language" the value "De" as expected. Due to the code in the section [FilesMove] after a restart of the program the UI should appear in German. But once again the app appears in English. This strange behavior I can not quite understand. Is there an explanation for this?

  3. Question #3

    Apparently seems the section [LanguageFile] play a crucial role in this context. But how this section interacts in datail?

Aluísio A. S. G.
Offline
Last seen: 7 years 9 months ago
DeveloperTranslator
Joined: 2010-11-09 17:43
[LanguageFile] gets the language from a file

See here for details.
Also, please don't move stuff into settings (or use it for app settings, for that matter).

Previously known as kAlug.

Ken Herbert
Ken Herbert's picture
Offline
Last seen: 6 hours 26 min ago
DeveloperModerator
Joined: 2010-05-25 18:19
Not strange at all

That is how it should work.

To simplify the process for your specific example:
1. The Launcher tries to get the language of the Platform in the format you specified (Base=%PortableApps.comLanguageCode%) but can't, because you are not using the Platform.
2. Because %PAL:LanguageCustom% has not been set, the Launcher sets it to "en" (Default=en).

What is happening because you have [LanguageFile] commented out:
3. The Launcher performs [FileWrite2] replacing the .ini file's current language with %PAL:LanguageCustom% (so it replaces "Hu" with "en").
4. The app launches in English.

What would happen if you had a [LanguageFile] section:
3. The [LanguageFile] section will be processed and %PAL:LanguageCustom% will be set to "Hu".
4. The Launcher performs [FileWrite2] replacing the .ini file's current language (so it replaces "Hu" with "Hu").
5. The app launches in Hungarian.

tapsklaps
Offline
Last seen: 5 years 6 months ago
Developer
Joined: 2010-10-17 08:11
brilliant explanation

At this point, first of all, many many thanks for this very excellent and conclusive answer to all my questions Smile Thus is now my understanding regarding the complex area of ​​language change considerably expanded.

Mistakenly, I have assumed until now, that the environment variable %PAL:LanguageCustom% occurs only in the context of the platform, where it will be applied. Based on your explanations it was now clear for me, that this variable is also applied outside of the platform.

You have mentioned in No. 2 of your first paragraph , that in the case of %PAL:LanguageCustom% has not been set, the Launcher sets it to "en" (Default=en). Refers your note in brackets on my code "Default = en" in the section [Language] in the file DragoPortable.ini? Or does it means rather, that the launcher basically set this variable %PAL:LanguageCustom% to "en", when it is not yet set? (no matter how I specify "Default" in the section [Language])

In your 3rd Paragraph you vividly illustrate the importance of the section [LanguageFile]. Accordingly I conclude, that the main task of the section [LanguageFile] is to determine the environment variable %PAL:LanguageCustom%.

Ken Herbert
Ken Herbert's picture
Offline
Last seen: 6 hours 26 min ago
DeveloperModerator
Joined: 2010-05-25 18:19
Glad to help

Yes, by (Default=en) I do mean what you have put in your [Language] section. This value should also be in the format you specify in [Language]:Base
eg. Base=%PortableApps.comLocaleName% would require Default=English, but %PortableApps.comLocaleglibc% would require Default=en_US.

A more complex case may also require [Language]:CheckIfExists to make sure a particular language file exists at a given path before switching to the selected language.

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 5 months 2 days ago
DeveloperModerator
Joined: 2008-07-24 18:46
comments

Because you have Default=en in [Language] in DragoPortable.ini, if %PAL:LanguageCustom% is not set by either the platform or the LanguageFile section, it will be set to en. If Default=de, it would set to de instead.

Right, LanguageFile is to determine what to set LanguageCustom to when NOT launched from the platform. If the app is launched from the platform, LanguageFile is ignored.

Log in or register to post comments