Change lang in runtime
Hi,
could you, please, make small simple demo of changing translation (ideally from list of filenames) (Of course, I know that I should restart my App then) ? (I tried to look on BTM source code, but there is lot of code, lot of units (dependency on devexpress), so I’m a little lost)
Second question is about exporting to csv - as our app is bigger, there is lot of RS, which we don’t need to translate, could we export to csv only lines with translate flag? See #35
Thanks
Comments (6)
-
-
- edited description
- changed title to Change lang in runtime
- changed component to Documentation
-
assigned issue to
-
- changed status to open
-
repo owner - changed status to resolved
Updated HelloWorld example with language module selection. Fixes
#34→ <<cset 2f8f7f146cc1>>
-
reporter Ou, great, many thanks.
Could you also add some manual lang on startup in this example ? (As simple paramStr for example : app.exe DE start this app in DE. I don’t like registry and this app could be on computer with more application (one user account, but more users with more langs, so startup parameter is great for me )
-
The example uses the automatic language module loading mechanism built into Delphi’s RTL. This mechanism selects the language module based on the user’s Windows language settings. In the vast majority of cases this is what people expect and want. The only way to override the selected language, using this method, is to use the registry as documented in the Delphi help.
However if you want complete control over what language module is loaded you can bypass the RTLs mechanism and instead use the same method BTM itself uses. Something like this (in your project source file):
uses amLocale, amLocalization.Utils, ... procedure LoadLanguageModule; var Language: string; LocaleItem: TLocaleItem; begin if (not FindCmdLineSwitch('language', Language, True, [clstValueAppended])) then exit; LocaleItem := TLocaleItems.FindLocaleName(Language); if (LocaleItem <> nil) then LocalizationTools.LoadResourceModule(LocaleItem.Locale); end; begin LoadLanguageModule; ... end.
You can the specify the language using
YouApplication.exe -language:DE
- Log in to comment
One topic per issue please. I have created a new issue, regarding the CSV export, on your behalf:
#35.I know there’s need for better documentation but I will see if I can’t create a small example of how to change the language at run-time. It’s fairly simple.
Until then I suggest you read the Delphi documentation on the subject (it applies to BTM as well):
You can find the functions I use to load resource modules in amLocalization.Utils.pas and here is the code where I load the translation in BTM itself.