Author Topic: Howto: setup/update a locale-specific mo-file from a bash script  (Read 2616 times)

Offline pinoc

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2843
    • other projects...
The points below should help to illustrate this process using getopenoffice and German as an example. Please amend the example for your language.

1) create a new empty directory and copy the bash-program (getopenoffice) in there

2) to setup the pot-file, open a konsole in this directory, and enter the command:
Code: [Select]
bash --dump-po-strings getopenoffice | xgettext -L PO -o getopenoffice.pot -
3) to setup a German po-file from the pot-file, enter the command (just press enter, provide your email-address if you want to, ignore the urlget error and wait for the command to finish):
Code: [Select]
msginit -l de -i getopenoffice.pot -o getopenoffice.poor for a Spanish file you would use:
Code: [Select]
msginit -l es -i getopenoffice.pot -o getopenoffice.poNote: if you translate more than one language make sure to use a different filename for each po-file to not overwrite the previous language po-file!

4) open the po-file with poedit (install poedit from Synaptic) In poedit, go to Catalog -> Settings -> Project Info tab: you must specify a valid project name and version (here, getopenoffice 1.0), otherwise you can not save your translation work! Please also insert your language and country and under 'Source code charset': utf-8. Then select any original string with a mouse-click and enter the corresponding translated text in the bottom field in poedit. A good idea is to copy the entire displayed text in the first window at the bottom of poedit and then copy it to the last bottom window for translation. This way you will maintain the text layout including the special characters like linebreak (\\n) or exclamation mark (\\!), or other parameter variables like '$idx', just leave those as they are. Please note that the translated text will be moved to the bottom of the list in poedit when you save your project.

5) In case of a new program version you can easily update your existing work from the po-file of the previous version:
a) follow the step 1 above on the new program version to setup an updated pot-file.
b) open your previous po-file in poedit and then choose: Catalog -> Update from POT file...
and then select the new updated pot-file. This will show you the new changes and merge them into your existing po-file.
After that, don't forget to also change the version number in the Catalog -> Settings -> Project Info tab of your updated po-file.

6) when you finished translating, save your project. Poedit will save it as editable po-file as well as a compiled mo-file. To control your work and to see if all works as expected, follow these steps (again, exemplified for German, amend for your language):
- ensure to have a localized system of your language used for the translation. For our German example, you must work in a German localized PCLinuxOS and the current version of the (getopenoffice) script should be in its final place (here, /usr/bin/).
- Ok, now open a konsole in the directory where you worked on the translation and enter
Code: [Select]
cp getopenoffice-de.mo getopenoffice.mo- as root do:
Code: [Select]
cp getopenoffice.mo /usr/share/locale/de/LC_MESSAGES/ (or i.e. for Spanish you would have to copy to /usr/share/locale/es/LC_MESSAGES/)
- execute the script:
Code: [Select]
/usr/bin/getopenoffice and you should now see and can control your translated text.

7) Once you are satiesfied with your results submit the (po and) mo-file (maybe best with an added language extension, i.e., getopenoffice-GERMAN.mo to avoid the risk of overwriting different localized mo-files) to the package translation section. The packagers can then download these mo-files, remove the Language notation and put the locale in the appropriate place. Please use the following notation in the title when submitting a mo-file (here for the German example, amend to your language):
Quote
[ -T- getopenoffice] translation to German (done)


Since you are all eagerly waiting to test the steps above, please find attached the latest GOO 1.0. Download, remove the .txt, md5sum: d13132a6858d75fc0fb899e4b6457db3

Thank you for your help!

regards,
-pinoc

Edit: changed the attached version from 0.9 to 1.0


[attachment deleted by admin]
« Last Edit: August 11, 2009, 08:23:48 AM by pinoc »

Offline melodie

  • Hero Member
  • *****
  • Posts: 5942
  • XMMP=Jabber, free instant messaging protocol !
    • PCLinuxOS Fr
Re: Howto: setup/update a locale-specific mo-file from a bash script
« Reply #1 on: April 17, 2011, 05:41:47 PM »
Hi,

I just tested Leiche's bash_trans script that makes it automatic, and it's really fine. Once installed, we have Bash translation script in the right-click menu and when we select this right-click menu and then select the file to get the pot and po file it opens a window to select the desired file.

A few seconds only are necessary to get the 2 files and we can start translating at once (provided poedit is already configured with the translator's preferences).

Regards,
Mélodie

melodie at swissjabber dot ch - IRC #pclinuxos-fr sur freenode