Difference between revisions of "Internationalization"

From Code::Blocks
m (→‎Create and use the .mo file: Enhance intructions)
 
(54 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
[[Category:Developer Documentation]]
 
[[Category:Developer Documentation]]
  
This article is about how to realize and use localized C:B. All the works have been done under Windows XP SP2.
+
This article is about how to realize and use localized C:B.
 +
 
 +
Original article written by heromyth.
 +
 
 +
Reviewed by gd_on.
  
 
== Get the English POT file ==
 
== Get the English POT file ==
  
The english POT file url is:
+
The url of the english POT file is at:
 +
 
 +
for the '''original site''' (''but obsolete'') : https://translations.launchpad.net/codeblocks/trunk/+pots/codeblocks
 +
 
 +
or
 +
 
 +
for a '''new site''' : https://translations.launchpad.net/codeblocks-gd
 +
 
 +
More information can be seen at: https://forums.codeblocks.org/index.php/topic,10204.msg70638.html.
  
https://developer.berlios.de/patch/?func=detailpatch&patch_id=822&group_id=5358
+
or :
 +
 
 +
https://forums.codeblocks.org/index.php/topic,1022.msg159075.html#msg159075
 
   
 
   
I will update this file periodically. Of course, you can use the tool which I have created (see belown) to generate the POT file.
+
Of course, you can run extract.cmd (shown below) to generate the POT file. It extracts all the text chains from .cpp files and .xrc file, for the main core and the contribs plugins. It also extract strings from compiler's xml files and descriptions fields found in manifest*.xml from plugins. You can place it in a subdirectory of your codeblocks_src (created by svn for example), as src\i18n or a specific src\My_i18n.
  
The content of the tool which is named as '''intl.bat''' is below:
+
This tool uses several unix-like tools as find, rm, grep, xargs, xgettext, msgcat, sed. Some of them are available with many MinGW distributions or Msys2.
  
  rem ======= Begin of intl.bat =======
+
'''Note''' : you '''must''' use the unix-like find.exe, ''not'' the Windows one : they have not the same syntax. So, the unix-like find.exe must be found in your PATH, before the Windows one!
 +
 
 +
The tool wxrc is used in these command files. You can find the source in wxWidgets/utils and build it.
 +
 
 +
For your convenience, some unix tools (extracted from msys2) and a wxrc.exe (statically linked with wxWidgets 3.2.1, 64 bit) can be downloaded from a git repository [https://github.com/gerard-durand/codeblocks_gd_extract_tools/tree/master/Unix_Tools Unix-Tools]
 +
 
 +
The content of '''extract.cmd''' is below (or you can download it from a git repository [https://github.com/gerard-durand/codeblocks_gd_extract_tools Extract-Tools] containing a copy of unix tools and wxrc):
 +
 
 +
  rem ======= Begin of extract.cmd =======
 +
 
 +
echo off
 +
echo ****************************
 +
echo * creating core .pot files *
 +
echo ****************************
 +
echo *
 +
find ../sdk ../src | grep -F .cpp | grep -v svn-base | grep -v .svn | grep -v .cpp.org | xargs xgettext --keyword=_ -o codeblocks1.pot 2> log.txt
 +
find ../sdk ../src ../include | grep -F .h  | grep -v svn-base | grep -v .svn | grep -v .h.org | grep -v html | xargs xgettext --keyword=_ -o codeblocks2.pot 2>> log.txt
 +
find ../scripts | grep -F .script | grep -v svn-base | grep -v .svn | xargs xgettext --keyword=_ -o codeblocks3.pot 2>> log.txt
 +
find ../plugins/scriptedwizard/resources | grep -F .script | grep -v svn-base | grep -v .svn | xargs xgettext --keyword=_ -o codeblocks4.pot 2>> log.txt
 +
find codeblocks1.pot >  files.txt
 +
find codeblocks2.pot >> files.txt
 +
find codeblocks3.pot >> files.txt
 +
find codeblocks4.pot >> files.txt
 
   
 
   
  @echo off
+
  find ../plugins | grep -v contrib | grep -F .cpp | grep -v .svn | grep -v svn-base | grep -v .patch | xargs xgettext --keyword=_ -o  coreplugins1.pot 2>> log.txt
wxrc src\resources\*.xrc -g -o  src\src-xrc.cpp
+
  find ../plugins | grep -v contrib | grep -F .h  | grep -v .svn | grep -v svn-base | grep -v html  | xargs xgettext --keyword=_ -o coreplugins2.pot 2>> log.txt
wxrc sdk\resources\*.xrc -g -o  sdk\sdk-xrc.cpp
+
  find coreplugins1.pot >> files.txt
  wxrc plugins\astyle\resources\*.xrc -g -o  plugins\astyle\astyle-xrc.cpp
+
find coreplugins2.pot >> files.txt
  wxrc plugins\classwizard\resources\*.xrc -g -o plugins\classwizard\classwizard-xrc.cpp
+
  wxrc plugins\codecompletion\resources\*.xrc -g -o  plugins\codecompletion\codecompletion-xrc.cpp
+
echo *
  wxrc plugins\compilergcc\resources\*.xrc -g -o  plugins\compilergcc\compilergcc-xrc.cpp
+
echo *******************************
  wxrc plugins\debuggergdb\resources\*.xrc -g -o plugins\debuggergdb\debuggergdb-xrc.cpp
+
  echo * creating contrib .pot files *
  wxrc plugins\defaultmimehandler\resources\*.xrc -g -o plugins\defaultmimehandler\defaultmimehandler-xrc.cpp
+
echo *******************************
  wxrc plugins\todo\resources\*.xrc -g -o plugins\todo\todo-xrc.cpp
+
echo *
  wxrc plugins\autosave\*.xrc -g -o  plugins\autosave\autosave-xrc.cpp
+
wxrc plugins\scriptedwizard\resources\plugins\*.xrc -g -o  plugins\scriptedwizard\resources\plugins\scriptedwizard-xrc.cpp
+
  find ../plugins/contrib | grep -F .cpp | grep -v .svn | grep -v svn-base > file_c.txt
  wxrc plugins\scriptedwizard\resources\wxwidgets\*.xrc -g -o  plugins\scriptedwizard\resources\wxwidgets\wxwidgets-xrc.cpp
+
  find ../plugins/contrib | grep -F .h  | grep -v .svn | grep -v svn-base | grep -v html | grep -v .gch >> file_c.txt
  rem .
+
  xgettext -f file_c.txt --keyword=_ -o  contribplugins.pot 2>> log.txt
if not exist po md po
+
find contribplugins.pot >> files.txt
  rem .
+
xgettext -C -n -k_ -o po\codeblocks.pot include\*.h
+
echo *
xgettext -C -n -k_ -j -o po\codeblocks.pot src\*.cpp src\*.h
+
echo ***************************************
  xgettext -C -n -k_ -j -o po\codeblocks.pot src\wxAUI\*.cpp src\wxAUI\*.h
+
echo * creating .cpp files from .xrc files *
  xgettext -C -n -k_ -j -o po\codeblocks.pot sdk\*.cpp
+
echo ***************************************
  xgettext -C -n -k_ -j -o po\codeblocks.pot sdk\propgrid\src\propgrid\*.cpp include\propgrid\include\wx\propgrid\*.h
+
echo *
  xgettext -C -n -k_ -j -o po\codeblocks.pot sdk\wxFlatNotebook\src\wxFlatNotebook\*.cpp include\wxFlatNotebook\include\wx\wxFlatNotebook\*h
+
  find ../src/resources | grep -F .xrc | grep -v .svn | grep -v svn-base | xargs wxrc -g -o src_xrc.cpp 2>> log.txt
  xgettext -C -n -k_ -j -o po\codeblocks.pot sdk\scripting\bindings\*.cpp include\scripting\bindings\*.h
+
  find ../sdk/resources | grep -F .xrc | grep -v .svn | grep -v svn-base | xargs wxrc -g -o sdk_xrc.cpp 2>> log.txt
  rem .
+
  find ../plugins | grep -F .xrc | grep -v .svn | grep -v svn-base | xargs wxrc -g -o plugins_xrc2.cpp 2>> log.txt
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\codecompletion\*.cpp plugins\codecompletion\*.h
+
  REM Why next lines? modifications in recent wxrc? string modif? Only one line (1515) in compiler_options.xrc has a problem, though the same syntax in a previous line (1151) is OK !
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\codecompletion\parser\*.cpp plugins\codecompletion\parser\*.h
+
sed -i 's/\"Compiling <file>...\"/\\\"Compiling <file>...\\\"/g' plugins_xrc2.cpp
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\astyle\*.cpp plugins\astyle\*.h
+
  REM Eliminate a truncated string containing only "At ".
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\astyle\astyle\*.cpp plugins\astyle\astyle\*.h
+
sed -i 's/\"else\"/\\\"else\\\"/g' plugins_xrc2.cpp
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\classwizard\*.cpp plugins\classwizard\*.h
+
  REM In .xrc files, there is no way to indicate that a string is translatable or not. So those following grep - v try to eliminate some lines.
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\codecompletion\*.cpp plugins\codecompletion\*.h
+
  grep -v msp430x plugins_xrc2.cpp | grep -v dragon_ | grep -v msp430x | grep -v cc430x | grep -v jtag1 | grep -v jtag2 | grep -v jtagm | grep -v atxmega | grep -v atmega | grep -v attiny | grep -v at86 | grep -v at90 | grep -v AT90 | grep -v TC1 > plugins_xrc.cpp
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\compilergcc\*.cpp plugins\compilergcc\*.h
+
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\debuggergdb\*.cpp plugins\debuggergdb\*.h
+
del plugins_xrc2.cpp
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\defaultmimehandler\*.cpp plugins\defaultmimehandler\*.h
+
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\todo\*.cpp plugins\todo\*.h
+
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\xpmanifest\*.cpp plugins\xpmanifest\*.h
+
echo *
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\autosave\*.cpp plugins\autosave\*.h
+
echo *************************************************
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\scriptedwizard\*.cpp plugins\scriptedwizard\*.h plugins\scriptedwizard\resources\*.script
+
  echo * creating .pot files from those local new .cpp *
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\scriptedwizard\resources\plugins\templates\*.cpp plugins\scriptedwizard\resources\plugins\templates\*.h
+
  echo *************************************************
  xgettext -C -n -k_ -j -o po\codeblocks.pot plugins\scriptedwizard\resources\wxwidgets\common\*.cpp plugins\scriptedwizard\resources\wxwidgets\common\*.h
+
echo *
  pause
+
find . | grep -F .cpp | xargs xgettext --keyword=_ -o xrc.pot 2>> log.txt
  rem ======= End of intl.bat =======
+
sed "s/\$\$*/\$/g" xrc.pot > xrc.pox
 +
  sed 's/\\\\\\\\/\\\\/g' xrc.pox > xrc.pot
 +
find xrc.pot >> files.txt
 +
 +
REM Extracting strings from files as .xml, .xrc need more work because there is nothing to speify than a string is translatable or not.
 +
REM May also need additionnal filters if the serached string is on several lines.
 +
 +
echo *
 +
echo *************************************************
 +
echo * extracting strings from .xml compilers files  *
 +
echo *************************************************
 +
echo *
 +
  find ../plugins/compilergcc/resources/compilers | grep -F .xml | xargs grep -F "CodeBlocks_compiler name" > src_xml.cpp 2>> log.txt
 +
find ../plugins/compilergcc/resources/compilers | grep -F .xml | xargs grep -F "Option name"  >>  src_xml.cpp 2>> log.txt
 +
find ../plugins/compilergcc/resources/compilers | grep -F .xml | xargs grep -F "Category name" >>  src_xml.cpp 2>> log.txt
 +
  find ../plugins/compilergcc/resources/compilers | grep -F .xml | xargs grep -F "checkMessage"  >>  src_xml.cpp 2>> log.txt
 +
  REM In .xml files, there is no way to indicate that a string is translatable or not. So those following grep - v try to eliminate some lines.
 +
  grep -v mabi src_xml.cpp | grep -v mno | grep -v apcs | grep -v mtpcs | grep -v mshed | grep -v msoft | grep -v mhard | grep -v mfpe | grep -v msched | grep -v mlong | grep -v mpic | grep -v mcirrus | grep -v mcalle | grep -v mpoke | grep -v mwords | grep -v "MSP430 1" | grep -v "MSP430 2" | grep -v "MSP430 3" | grep -v "MSP430 4" | grep -v "MSP430 5" | grep -v "MSP430 6" | grep -v "MSP430 E" | grep -v "MSP430 W" | grep -v "MSP430 MS" | grep -v "MSP430 G4" | grep -v "CC430 5" | grep -v "CC430 6" | grep -v ATmega | grep -v Atmega | grep -v atmega | grep -v ATXmega | grep -v AT90 | grep -v AT43 | grep -v AT86 | grep -v AT76 | grep -v ATA | grep -v ata | grep -v ATtiny | grep -v Attiny | grep -v attiny | grep -v mcpu | grep -v TC1 > src_xml2.cpp
 +
  xgettext -a -o xml.pox src_xml2.cpp
 +
sed "s/&quot;/\\\\""/g" xml.pox > xml1.pot
 +
  find xml1.pot >> files.txt
 +
 +
echo *
 +
echo *************************************************"
 +
echo * extracting strings from manifest*.xml files  *"
 +
echo *************************************************"
 +
echo *
 +
 +
REM On Windows, the find option -name manifest*.xml is not (still) accepted (msys2 version), so the output is filtered with 2 -F options.
 +
 +
  find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs grep -F "title"  >>  src_xml_title.cpp 2>> log.txt
 +
  xgettext -a -s -o xml2_a.pot src_xml_title.cpp
 +
find xml2_a.pot >> files.txt
 +
REM The find for "title" does not work correctly for "description" if the string expands on several lines ! Only the first line is kept => the extracted text is truncated.
 +
REM With the following version, the string begin with "description" line and ends on "author" line => this implies than the order of the fields are the same in all manifests.
 +
REM More, if in manifest*.xml, in the description string, there is a CR/LF, it should be kept in the original string, because even if poedit "complains" the translation takes it into account.
 +
  find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs sed -n -e "/description/,/>/p" | sed '/author/d' | sed ":a;N;$!ba;s/\n/\\\n/g" | sed 's/""//g' | sed "s/&quot;/\\\\""/g" | sed "s/&amp;/\&/g" > src_xml_desc.cpp     2>> log.txt
 +
  xgettext -a -s -o xml2_b.pot src_xml_desc.cpp
 +
find xml2_b.pot >> files.txt
 +
 +
REM for keyword thanksTo
 +
  find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs sed -n -e "/thanksTo/,/>/p" | sed '/license/d'  | sed ":a;N;$!ba;s/\n/\\\n/g" | sed 's/""//g' | sed "s/&quot;/\\\\""/g" | sed "s/&amp;/\&/g" >  src_xml_thanks.cpp 2>> log.txt
 +
  xgettext -a -s -o xml2_c.pot src_xml_thanks.cpp
 +
find xml2_c.pot >> files.txt
 +
 +
REM for keyword authort: need to modify manifest.xml in wxSmithAUI because author contains characters with accents.
 +
  REM Add the = sign to avoid authorEmail and/or authorWeb lines which does not need to be translated
 +
find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs sed -n -e "/author=/,/>/p" | sed '/authorEmail/d' | sed ":a;N;$!ba;s/\n/\\\n/g" | sed 's/""//g' | sed "s/&quot;/\\\\""/g" | sed "s/&amp;/\&/g" >  src_xml_author.cpp 2>> log.txt
 +
  xgettext -a -s -o xml2_d.pot src_xml_author.cpp
 +
find xml2_d.pot >> files.txt
 +
 +
REM for keyword license (single line); include the = sign to be sure that lines containing the word license in a sentence are not kept.
 +
  find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs grep -F "license="  >>  src_xml_lic.cpp 2>> log.txt
 +
  xgettext -a -s -o xml2_e.pot src_xml_lic.cpp
 +
find xml2_e.pot >> files.txt
 +
 +
echo *
 +
echo **********************************
 +
echo * Merging and sorting .pot files *
 +
echo **********************************
 +
echo *
 +
  msgcat -s -f files.txt -o All_codeblocks.pox 2>> log.txt
 +
rm -f *.pot *.cpp files.txt file_c.txt
 +
  sed "s/#, c-format//g" All_codeblocks.pox > All_codeblocks.pot
 +
 +
rm -f *.pox
 +
 +
echo *
 +
echo ***************
 +
echo * The END*!!! *
 +
echo ***************
 +
  echo on
 +
 +
  rem ======= End of extract.cmd =======
  
 
== The tools for translation ==
 
== The tools for translation ==
  
 
Usually, we use the poEdit tool which can be downloaded [http://www.poedit.net/download.php here].
 
Usually, we use the poEdit tool which can be downloaded [http://www.poedit.net/download.php here].
 +
 +
Of course, you can do the translation directly on [https://translations.launchpad.net/codeblocks-gd Launchpad].
 +
 +
You'll find on Launchpad, two available downloads : a .po file, that you can use to edit or modify it, and a .mo file, a compiled ready to use in Code::Blocks. It's name may be quite long, but it does not matter. Only the extension is important.
  
 
== Translating with poEdit ==
 
== Translating with poEdit ==
  
Rename codeblocks.pot into codeblocks.po. Use poEdit to open the file codeblocks.po. Change a few settings like:
+
Rename or copy All_codeblocks.pot into All_codeblocks.po. Use poEdit to open the file All_codeblocks.po. Change a few settings like:
  
 
[File]->[Preferences]->[Personalize]
 
[File]->[Preferences]->[Personalize]
Line 71: Line 184:
 
If Code::Blocks is compiled with Unicode, the charset should be set to utf-8; If Code::Blocks is compiled with ANSI, the charset should be set to your own language charset like gb2312, koi8-r etc.
 
If Code::Blocks is compiled with Unicode, the charset should be set to utf-8; If Code::Blocks is compiled with ANSI, the charset should be set to your own language charset like gb2312, koi8-r etc.
  
After these settings are done, you can start translating. Don't be fooled, it's a hard work! During the process, of course, you can use your translation at any time.
+
After these settings are done, you can start translating. Don't be fooled, it's a long work! During the process, of course, you can use your translation at any time.
 +
 
 +
You can also download the .po file from Launchpad, work on it with poedit locally on your machine, and re-upload it on Launchpad to update and share your work.
 +
 
 +
'''Note:''' It may be necessary to approve this work, and sometimes to validate your own translations (or wait for someone else to validate them).
  
 
== Create and use the .mo file ==
 
== Create and use the .mo file ==
  
Pressing Ctrl+S in poEdit, you can get a *.mo file like codeblocks.mo which is what we need. To use codeblocks.mo, we just place it into C:\Program Files\CodeBlocks\share\CodeBlocks\locale\<lang>\LC_MESSAGES or C:\Program Files\CodeBlocks\share\CodeBlocks\locale\<lang>. My language is Chinese and I have installed C::B into E:\, so I place codeblocks.mo into E:\Program Files\CodeBlocks\share\CodeBlocks\locale\zh_CN.
+
Pressing Ctrl+S in poEdit, you can get a *.mo file like All_codeblocks.mo which is what we need. To use All_codeblocks.mo, we just place it into C:\Program Files\CodeBlocks\share\CodeBlocks\locale\<lang>\. My language is French and I have installed C::B into C:\, so I place All_codeblocks.mo into C:\Program Files\CodeBlocks\share\CodeBlocks\locale\fr_FR.
  
If you want to use codeblocks.mo under Linux or Unix, you just place it into /usr/X11R6/share/locale/<lang>/LC_MESSAGES/. For example, I put it into /usr/X11R6/share/locale/zh_CN/LC_MESSAGES/ under FreeBSD.
+
If you want to use All_codeblocks.mo under Linux or Unix, you just place it into /usr/X11R6/share/locale/<lang>/LC_MESSAGES/ or in the share/locale/<lang< sub-directory of your codeblocks installation, as in Windows (may be something like /usr/share/codeblocks/locale/<lang> (for me <lang> is fr_FR). Create sub-directories if necessary.
  
 
Details about internationalization using wxWidgets can be found in the wxWidgets docs.
 
Details about internationalization using wxWidgets can be found in the wxWidgets docs.
 +
 +
You will also need the wxWidgets' *.mo file for your language. Download the *.po file from [https://github.com/wxWidgets/wxWidgets/tree/master/locale here] and generate the *.mo file (using poEdit), or get the *.mo file directly from the wxWidgets' release used when compiling C::B. Copy this file to the folder specified above.
  
 
== Let Code::Blocks support your language ==
 
== Let Code::Blocks support your language ==
  
If you want Code::Blocks to support your language, you must modify the file '''\codeblocks\src\src\appglobals.cpp'''. In it, you can search for the word 'Chinese' to see the example. There are two vars about it:
+
In Code::Blocks menu, Settings, Environment, View, you'll find a check-box for Internationalization. If you check it, you'll normally find your language in the dropdown list.
 
 
const wxString langs[LANGUAGES_SIZE]
 
const int locales[LANGUAGES_SIZE]
 
 
 
== Troubleshooting ==
 
 
 
If you have any questions, you can send me a mail: zxpmyth at yahoo.com.cn.
 

Latest revision as of 11:08, 1 October 2024


This article is about how to realize and use localized C:B.

Original article written by heromyth.

Reviewed by gd_on.

Get the English POT file

The url of the english POT file is at:

for the original site (but obsolete) : https://translations.launchpad.net/codeblocks/trunk/+pots/codeblocks

or

for a new site : https://translations.launchpad.net/codeblocks-gd

More information can be seen at: https://forums.codeblocks.org/index.php/topic,10204.msg70638.html.

or :

https://forums.codeblocks.org/index.php/topic,1022.msg159075.html#msg159075

Of course, you can run extract.cmd (shown below) to generate the POT file. It extracts all the text chains from .cpp files and .xrc file, for the main core and the contribs plugins. It also extract strings from compiler's xml files and descriptions fields found in manifest*.xml from plugins. You can place it in a subdirectory of your codeblocks_src (created by svn for example), as src\i18n or a specific src\My_i18n.

This tool uses several unix-like tools as find, rm, grep, xargs, xgettext, msgcat, sed. Some of them are available with many MinGW distributions or Msys2.

Note : you must use the unix-like find.exe, not the Windows one : they have not the same syntax. So, the unix-like find.exe must be found in your PATH, before the Windows one!

The tool wxrc is used in these command files. You can find the source in wxWidgets/utils and build it.

For your convenience, some unix tools (extracted from msys2) and a wxrc.exe (statically linked with wxWidgets 3.2.1, 64 bit) can be downloaded from a git repository Unix-Tools

The content of extract.cmd is below (or you can download it from a git repository Extract-Tools containing a copy of unix tools and wxrc):

rem ======= Begin of extract.cmd =======
  
echo off
echo ****************************
echo * creating core .pot files *
echo ****************************
echo * 
find ../sdk ../src | grep -F .cpp | grep -v svn-base | grep -v .svn | grep -v .cpp.org | xargs xgettext --keyword=_ -o codeblocks1.pot 2> log.txt
find ../sdk ../src ../include | grep -F .h  | grep -v svn-base | grep -v .svn | grep -v .h.org | grep -v html | xargs xgettext --keyword=_ -o codeblocks2.pot 2>> log.txt
find ../scripts | grep -F .script | grep -v svn-base | grep -v .svn | xargs xgettext --keyword=_ -o codeblocks3.pot 2>> log.txt
find ../plugins/scriptedwizard/resources | grep -F .script | grep -v svn-base | grep -v .svn | xargs xgettext --keyword=_ -o codeblocks4.pot 2>> log.txt
find codeblocks1.pot >  files.txt
find codeblocks2.pot >> files.txt
find codeblocks3.pot >> files.txt
find codeblocks4.pot >> files.txt

find ../plugins | grep -v contrib | grep -F .cpp | grep -v .svn | grep -v svn-base | grep -v .patch | xargs xgettext --keyword=_ -o  coreplugins1.pot 2>> log.txt
find ../plugins | grep -v contrib | grep -F .h   | grep -v .svn | grep -v svn-base | grep -v html   | xargs xgettext --keyword=_ -o coreplugins2.pot 2>> log.txt
find coreplugins1.pot >> files.txt
find coreplugins2.pot >> files.txt

echo *
echo *******************************
echo * creating contrib .pot files *
echo *******************************
echo *

find ../plugins/contrib	| grep -F .cpp | grep -v .svn | grep -v svn-base > file_c.txt
find ../plugins/contrib | grep -F .h   | grep -v .svn | grep -v svn-base | grep -v html | grep -v .gch >> file_c.txt
xgettext -f file_c.txt --keyword=_ -o  contribplugins.pot 2>> log.txt
find contribplugins.pot >> files.txt

echo *
echo ***************************************
echo * creating .cpp files from .xrc files *
echo ***************************************
echo *
find ../src/resources | grep -F .xrc | grep -v .svn | grep -v svn-base | xargs wxrc -g -o src_xrc.cpp 2>> log.txt
find ../sdk/resources | grep -F .xrc | grep -v .svn | grep -v svn-base | xargs wxrc -g -o sdk_xrc.cpp 2>> log.txt
find ../plugins | grep -F .xrc | grep -v .svn | grep -v svn-base | xargs wxrc -g -o plugins_xrc2.cpp 2>> log.txt
REM Why next lines? modifications in recent wxrc? string modif? Only one line (1515) in compiler_options.xrc has a problem, though the same syntax in a previous line (1151) is OK !
sed -i 's/\"Compiling <file>...\"/\\\"Compiling <file>...\\\"/g' plugins_xrc2.cpp
REM Eliminate a truncated string containing only "At ".
sed -i 's/\"else\"/\\\"else\\\"/g' plugins_xrc2.cpp
REM In .xrc files, there is no way to indicate that a string is translatable or not. So those following grep - v try to eliminate some lines.
grep -v msp430x plugins_xrc2.cpp | grep -v dragon_ | grep -v msp430x | grep -v cc430x | grep -v jtag1 | grep -v jtag2 | grep -v jtagm | grep -v atxmega | grep -v atmega | grep -v attiny | grep -v at86 | grep -v at90 | grep -v AT90 | grep -v TC1 > plugins_xrc.cpp

del plugins_xrc2.cpp


echo *
echo *************************************************
echo * creating .pot files from those local new .cpp *
echo *************************************************
echo *
find . | grep -F .cpp | xargs xgettext --keyword=_ -o xrc.pot 2>> log.txt
sed "s/\$\$*/\$/g" xrc.pot > xrc.pox
sed 's/\\\\\\\\/\\\\/g' xrc.pox > xrc.pot
find xrc.pot >> files.txt

REM Extracting strings from files as .xml, .xrc need more work because there is nothing to speify than a string is translatable or not.
REM May also need additionnal filters if the serached string is on several lines.

echo *
echo *************************************************
echo * extracting strings from .xml compilers files  *
echo *************************************************
echo *
find ../plugins/compilergcc/resources/compilers | grep -F .xml | xargs grep -F "CodeBlocks_compiler name" > src_xml.cpp 2>> log.txt
find ../plugins/compilergcc/resources/compilers | grep -F .xml | xargs grep -F "Option name"   >>  src_xml.cpp 2>> log.txt
find ../plugins/compilergcc/resources/compilers | grep -F .xml | xargs grep -F "Category name" >>  src_xml.cpp 2>> log.txt
find ../plugins/compilergcc/resources/compilers | grep -F .xml | xargs grep -F "checkMessage"  >>  src_xml.cpp 2>> log.txt
REM In .xml files, there is no way to indicate that a string is translatable or not. So those following grep - v try to eliminate some lines.
grep -v mabi src_xml.cpp | grep -v mno | grep -v apcs | grep -v mtpcs | grep -v mshed | grep -v msoft | grep -v mhard | grep -v mfpe | grep -v msched | grep -v mlong | grep -v mpic | grep -v mcirrus | grep -v mcalle | grep -v mpoke | grep -v mwords | grep -v "MSP430 1" | grep -v "MSP430 2" | grep -v "MSP430 3" | grep -v "MSP430 4" | grep -v "MSP430 5" | grep -v "MSP430 6" | grep -v "MSP430 E" | grep -v "MSP430 W" | grep -v "MSP430 MS" | grep -v "MSP430 G4" | grep -v "CC430 5" | grep -v "CC430 6" | grep -v ATmega | grep -v Atmega | grep -v atmega | grep -v ATXmega | grep -v AT90 | grep -v AT43 | grep -v AT86 | grep -v AT76 | grep -v ATA | grep -v ata | grep -v ATtiny | grep -v Attiny | grep -v attiny | grep -v mcpu | grep -v TC1 > src_xml2.cpp
xgettext -a -o xml.pox src_xml2.cpp
sed "s/"/\\\\""/g" xml.pox > xml1.pot
find xml1.pot >> files.txt

echo *
echo *************************************************"
echo * extracting strings from manifest*.xml files   *"
echo *************************************************"
echo *

REM On Windows, the find option -name manifest*.xml is not (still) accepted (msys2 version), so the output is filtered with 2 -F options.

find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs grep -F "title"  >>  src_xml_title.cpp 2>> log.txt
xgettext -a -s -o xml2_a.pot src_xml_title.cpp
find xml2_a.pot >> files.txt
REM The find for "title" does not work correctly for "description" if the string expands on several lines ! Only the first line is kept => the extracted text is truncated.
REM With the following version, the string begin with "description" line and ends on "author" line => this implies than the order of the fields are the same in all manifests.
REM More, if in manifest*.xml, in the description string, there is a CR/LF, it should be kept in the original string, because even if poedit "complains" the translation takes it into account.
find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs sed -n -e "/description/,/>/p" | sed '/author/d' | sed ":a;N;$!ba;s/\n/\\\n/g" | sed 's/""//g' | sed "s/"/\\\\""/g" | sed "s/&/\&/g" > src_xml_desc.cpp     2>> log.txt
xgettext -a -s -o xml2_b.pot src_xml_desc.cpp
find xml2_b.pot >> files.txt

REM for keyword thanksTo
find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs sed -n -e "/thanksTo/,/>/p" | sed '/license/d'   | sed ":a;N;$!ba;s/\n/\\\n/g" | sed 's/""//g' | sed "s/"/\\\\""/g" | sed "s/&/\&/g" >  src_xml_thanks.cpp  2>> log.txt
xgettext -a -s -o xml2_c.pot src_xml_thanks.cpp
find xml2_c.pot >> files.txt

REM for keyword authort: need to modify manifest.xml in wxSmithAUI because author contains characters with accents.
REM Add the = sign to avoid authorEmail and/or authorWeb lines which does not need to be translated
find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs sed -n -e "/author=/,/>/p" | sed '/authorEmail/d' | sed ":a;N;$!ba;s/\n/\\\n/g" | sed 's/""//g' | sed "s/"/\\\\""/g" | sed "s/&/\&/g" >  src_xml_author.cpp 2>> log.txt
xgettext -a -s -o xml2_d.pot src_xml_author.cpp
find xml2_d.pot >> files.txt

REM for keyword license (single line); include the = sign to be sure that lines containing the word license in a sentence are not kept.
find ../plugins | grep -F manifest | grep -F .xml | grep -v svn-base | grep -v .svn | xargs grep -F "license="  >>  src_xml_lic.cpp 2>> log.txt
xgettext -a -s -o xml2_e.pot src_xml_lic.cpp
find xml2_e.pot >> files.txt

echo *
echo **********************************
echo * Merging and sorting .pot files *
echo **********************************
echo *
msgcat -s -f files.txt -o All_codeblocks.pox 2>> log.txt
rm -f *.pot *.cpp files.txt file_c.txt
sed "s/#, c-format//g" All_codeblocks.pox > All_codeblocks.pot

rm -f *.pox

echo *
echo ***************
echo * The END*!!! *
echo ***************
echo on

rem ======= End of extract.cmd =======

The tools for translation

Usually, we use the poEdit tool which can be downloaded here.

Of course, you can do the translation directly on Launchpad.

You'll find on Launchpad, two available downloads : a .po file, that you can use to edit or modify it, and a .mo file, a compiled ready to use in Code::Blocks. It's name may be quite long, but it does not matter. Only the extension is important.

Translating with poEdit

Rename or copy All_codeblocks.pot into All_codeblocks.po. Use poEdit to open the file All_codeblocks.po. Change a few settings like:

[File]->[Preferences]->[Personalize]

[Catalog]->[Settings]->[Project info]->[Team/email/Language/Charset]

If Code::Blocks is compiled with Unicode, the charset should be set to utf-8; If Code::Blocks is compiled with ANSI, the charset should be set to your own language charset like gb2312, koi8-r etc.

After these settings are done, you can start translating. Don't be fooled, it's a long work! During the process, of course, you can use your translation at any time.

You can also download the .po file from Launchpad, work on it with poedit locally on your machine, and re-upload it on Launchpad to update and share your work.

Note: It may be necessary to approve this work, and sometimes to validate your own translations (or wait for someone else to validate them).

Create and use the .mo file

Pressing Ctrl+S in poEdit, you can get a *.mo file like All_codeblocks.mo which is what we need. To use All_codeblocks.mo, we just place it into C:\Program Files\CodeBlocks\share\CodeBlocks\locale\<lang>\. My language is French and I have installed C::B into C:\, so I place All_codeblocks.mo into C:\Program Files\CodeBlocks\share\CodeBlocks\locale\fr_FR.

If you want to use All_codeblocks.mo under Linux or Unix, you just place it into /usr/X11R6/share/locale/<lang>/LC_MESSAGES/ or in the share/locale/<lang< sub-directory of your codeblocks installation, as in Windows (may be something like /usr/share/codeblocks/locale/<lang> (for me <lang> is fr_FR). Create sub-directories if necessary.

Details about internationalization using wxWidgets can be found in the wxWidgets docs.

You will also need the wxWidgets' *.mo file for your language. Download the *.po file from here and generate the *.mo file (using poEdit), or get the *.mo file directly from the wxWidgets' release used when compiling C::B. Copy this file to the folder specified above.

Let Code::Blocks support your language

In Code::Blocks menu, Settings, Environment, View, you'll find a check-box for Internationalization. If you check it, you'll normally find your language in the dropdown list.