Recent

Author Topic: i18n questions.  (Read 2194 times)

Spyd

  • New member
  • *
  • Posts: 7
i18n questions.
« on: October 14, 2018, 10:34:34 pm »
I'm trying to make a project with i18n so it's in multiple languages, but I have some problems and questions.
  • I use "DefaultTranslator" so a "SetDefaultLanguage" is called with empty parameters, and that's supposed to check the app parameters and environment variables, and if not guess the OS's UI language, but a call to "GetDefaultLanguage" returns an empty string.
  • My application's default language is Spanish. I can set a new language with it's corresponding .po files, but once changed, I don't know how to get back to the default language. "SetDefaultLanguage('es');" nor "SetDefaultLanguage('');" do anything.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: i18n questions.
« Reply #1 on: October 14, 2018, 10:48:42 pm »
« Last Edit: October 14, 2018, 10:51:52 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: i18n questions.
« Reply #2 on: October 14, 2018, 10:58:10 pm »
I use following code to detect default language:
Code: Pascal  [Select][+][-]
  1. Result:=Copy(GetEnvironmentVariableUTF8('LANG'), 1, 5);
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

wp

  • Hero Member
  • *****
  • Posts: 11833
Re: i18n questions.
« Reply #3 on: October 14, 2018, 11:00:28 pm »
The .po template file (project.po) is not considered to be a translation file. In order to create one, copy it to project.es.po, open it in poedit and copy each string to the translation column. You can quickly do this by selecting all strings (click on the first string, scroll to the last string and SHIFT-click on it), then press CTRL+B; save as project.es.po. Then your default language file will be available like any other language file.

The routines that you mention, "SetDefaultLanguage" and "Get DefaultLanguage", are not available. Are you talking of "SetDefaultLang" and "GetDefaultLang" which are in LCLTranslator, not in DefaultTranslator?

I just tested with the translation sample project in the folder "examples/translation" of the Lazarus installation - "GetDefaultLang" returns my country symbol without any issues. Please have a look at this project, it is heavily commented.

Spyd

  • New member
  • *
  • Posts: 7
Re: i18n questions.
« Reply #4 on: October 14, 2018, 11:09:10 pm »
See Step-by-step instructions for creating multi-language applications, Everything else about translations and other pages in the Localization Category of the wiki. It's (almost) all there.
I have read all of those. That's how I got to make i18n work, but I can't find the answers to my questions in those pages.

Spyd

  • New member
  • *
  • Posts: 7
Re: i18n questions.
« Reply #5 on: October 14, 2018, 11:17:44 pm »
The .po template file (project.po) is not considered to be a translation file. In order to create one, copy it to project.es.po, open it in poedit and copy each string to the translation column. You can quickly do this by selecting all strings (click on the first string, scroll to the last string and SHIFT-click on it), then press CTRL+B; save as project.es.po. Then your default language file will be available like any other language file.
Well, I already thought of that, but I thought that there would be a better way to go back to the default translation without having to do all this pointless work.

The routines that you mention, "SetDefaultLanguage" and "Get DefaultLanguage", are not available. Are you talking of "SetDefaultLang" and "GetDefaultLang" which are in LCLTranslator, not in DefaultTranslator?
Yes, I meant SetDefaultLang & GetDefaultLang. I had written the initial post tired and annoyed and I didn't check for typos.

I just tested with the translation sample project in the folder "examples/translation" of the Lazarus installation - "GetDefaultLang" returns my country symbol without any issues. Please have a look at this project, it is heavily commented.
I just checked the example project and they do it the way you said, creating a dummy .po with all the strings copied. I guess this discards any elegant way to do it.

As for GetDefaultLang, I have put ShowMessage(GetDefaultLang); on the first line of the Form OnCreate, and it works (gives me 'es'). I'll have to debug it to see why in my project it returns an empty string.
« Last Edit: October 14, 2018, 11:21:13 pm by Spyd »

Spyd

  • New member
  • *
  • Posts: 7
Re: i18n questions.
« Reply #6 on: October 14, 2018, 11:21:52 pm »
Thanks for all the replies, I'll keep looking on this and post my findings here.

 

TinyPortal © 2005-2018