Version at: 22/02/2014, 18:44 vs. version at: 22/02/2014, 18:44 | ||
---|---|---|
1 | 1 | #Extracting UI Strings |
2 | 2 | |
3 | 3 | These instructions describe how to extract UI strings so that they can be translated. The original source of these instructions, stored on Assembla, is here: [1] |
4 | 4 | |
5 | 5 | [1]: https://www.assembla.com/spaces/tatoeba2/wiki/Internationalization |
6 | 6 | |
7 | 7 | |
8 | 8 | ##Markup for internationalized strings in the code |
9 | 9 | |
10 | 10 | In the code, whenever developers write strings that will have to be translated, they use a special function whose name consists of a double underscore. A script (CakePHP's "i18n extract" script) can later be run to scan the code and extract the strings that are passed to this function. |
11 | 11 | |
12 | 12 | __() function |
13 | 13 | |
14 | 14 | CakePHP has several functions in this vein, but this is the function we will use most of the time. Note the pair of underscores. |
15 | 15 | |
16 | 16 | __(‘some text’) => echo ‘some text’; |
17 | 17 | __(‘some text’, true) => return ‘some text’; |
18 | 18 | |
19 | 19 | The language used in the code will be English. |
20 | 20 | |
21 | 21 | ##Running cake i18n (on a Linux machine or virtual machine) |
22 | 22 | |
23 | 23 | Open a console. |
24 | 24 | Type : /var/http/tatoeba/cake/console/cake i18n |
25 | 25 | Choose : E (Extract POT file from source) |
26 | 26 | When asked if you want to merge all translations into a single file, say yes |
27 | 27 | Type in the path to app: /home/tatoeba/tatoeba-www/app |
28 | 28 | Type in the path to locale: /home/tatoeba/tatoeba-www/app/locale |
29 | 29 | Choose a name for the file that will be generated (in this example, default.pot): default.pot |
30 | 30 | Choose: Q (quit) |
31 | 31 | |
32 | PO file | |
32 | ##PO file | |
33 | 33 | |
34 | 34 | Note: it may be better to use Launchpad to create a new UI language rather than follow this manual procedure. |
35 | 35 | |
36 | 36 | Adding a new language (e.g., French): |
37 | 37 | |
38 | 38 | Create folder : /app/locale/fre/LC_MESSAGES |
39 | 39 | Copy-paste default.pot in this folder |
40 | 40 | Change it into default.po |
41 | 41 | Open default.po with PoEdit (http://www.poedit.net/) and translate. |
42 | 42 | Save. It will generate a *.mo file, which is used when replacing strings at runtime. |
43 | 43 | |
44 | 44 | If new strings are added: |
45 | 45 | |
46 | 46 | Follow the cake i18n instructions to generate the up-to-date POT file. |
47 | 47 | Open the PO file (PO, not POT). |
48 | 48 | In the menu : Catalog > Update from POT file… |
49 | 49 | Choose the POT file that was newly generated |
50 | 50 | |
51 | 51 | |
52 | Switching languages | |
52 | ##Switching languages | |
53 | 53 | |
54 | 54 | The language of the page is set through the URL. |
55 | 55 | Example : http://localhost/tatoeba2/fre/sentences/index |
56 | 56 | Resources |
57 | 57 | |
58 | 58 | http://blog.jaysalvat.com/articles/choix-des-langues-par-url-dans-cakephp.php |
59 | 59 | http://www.formation-cakephp.com/41/multilingue-18n-l10n |
60 | 60 | |
61 | 61 | |
62 | 62 | |
63 | 63 | |
diff view generated by jsdifflib |
Version at: 22/02/2014, 18:44
#Extracting UI Strings These instructions describe how to extract UI strings so that they can be translated. The original source of these instructions, stored on Assembla, is here: [1] [1]: https://www.assembla.com/spaces/tatoeba2/wiki/Internationalization ##Markup for internationalized strings in the code In the code, whenever developers write strings that will have to be translated, they use a special function whose name consists of a double underscore. A script (CakePHP's "i18n extract" script) can later be run to scan the code and extract the strings that are passed to this function. __() function CakePHP has several functions in this vein, but this is the function we will use most of the time. Note the pair of underscores. __(‘some text’) => echo ‘some text’; __(‘some text’, true) => return ‘some text’; The language used in the code will be English. ##Running cake i18n (on a Linux machine or virtual machine) Open a console. Type : /var/http/tatoeba/cake/console/cake i18n Choose : E (Extract POT file from source) When asked if you want to merge all translations into a single file, say yes Type in the path to app: /home/tatoeba/tatoeba-www/app Type in the path to locale: /home/tatoeba/tatoeba-www/app/locale Choose a name for the file that will be generated (in this example, default.pot): default.pot Choose: Q (quit) PO file Note: it may be better to use Launchpad to create a new UI language rather than follow this manual procedure. Adding a new language (e.g., French): Create folder : /app/locale/fre/LC_MESSAGES Copy-paste default.pot in this folder Change it into default.po Open default.po with PoEdit (http://www.poedit.net/) and translate. Save. It will generate a *.mo file, which is used when replacing strings at runtime. If new strings are added: Follow the cake i18n instructions to generate the up-to-date POT file. Open the PO file (PO, not POT). In the menu : Catalog > Update from POT file… Choose the POT file that was newly generated Switching languages The language of the page is set through the URL. Example : http://localhost/tatoeba2/fre/sentences/index Resources http://blog.jaysalvat.com/articles/choix-des-langues-par-url-dans-cakephp.php http://www.formation-cakephp.com/41/multilingue-18n-l10n
version at: 22/02/2014, 18:44
#Extracting UI Strings These instructions describe how to extract UI strings so that they can be translated. The original source of these instructions, stored on Assembla, is here: [1] [1]: https://www.assembla.com/spaces/tatoeba2/wiki/Internationalization ##Markup for internationalized strings in the code In the code, whenever developers write strings that will have to be translated, they use a special function whose name consists of a double underscore. A script (CakePHP's "i18n extract" script) can later be run to scan the code and extract the strings that are passed to this function. __() function CakePHP has several functions in this vein, but this is the function we will use most of the time. Note the pair of underscores. __(‘some text’) => echo ‘some text’; __(‘some text’, true) => return ‘some text’; The language used in the code will be English. ##Running cake i18n (on a Linux machine or virtual machine) Open a console. Type : /var/http/tatoeba/cake/console/cake i18n Choose : E (Extract POT file from source) When asked if you want to merge all translations into a single file, say yes Type in the path to app: /home/tatoeba/tatoeba-www/app Type in the path to locale: /home/tatoeba/tatoeba-www/app/locale Choose a name for the file that will be generated (in this example, default.pot): default.pot Choose: Q (quit) ##PO file Note: it may be better to use Launchpad to create a new UI language rather than follow this manual procedure. Adding a new language (e.g., French): Create folder : /app/locale/fre/LC_MESSAGES Copy-paste default.pot in this folder Change it into default.po Open default.po with PoEdit (http://www.poedit.net/) and translate. Save. It will generate a *.mo file, which is used when replacing strings at runtime. If new strings are added: Follow the cake i18n instructions to generate the up-to-date POT file. Open the PO file (PO, not POT). In the menu : Catalog > Update from POT file… Choose the POT file that was newly generated ##Switching languages The language of the page is set through the URL. Example : http://localhost/tatoeba2/fre/sentences/index Resources http://blog.jaysalvat.com/articles/choix-des-langues-par-url-dans-cakephp.php http://www.formation-cakephp.com/41/multilingue-18n-l10n