Translate
|
|
| Dennis Iversen |
| 16-Feb-2011 12:56:44 |
language.inc
Now we have our module. We have authentication, pagination, and a full featured blog for admin users. What is missing. It would be nice to translate all strings specified with the lang::translate static object call. Easy enough if you can use this command:
./coscli.sh translate --translate blog_simple en_GB
This will create two files. The first one is the language.inc file which is auto generated and located in blog_simple/lang/en_GB/language.inc. This file is only loaded when our module is loaded. For the translation to take effect the 'language' setting in our main config file (config/config.ini) needs to be set to en_GB. The newly created translation looks like this:
<?php
// Translation of file /home/dennis/www/coscms/modules/blog_simple/views/view.inc
$_COS_LANG_MODULE['blog_simple_written_by'] = 'blog_simple_written_by';
$_COS_LANG_MODULE['blog_simple_edit_entry'] = 'blog_simple_edit_entry';
$_COS_LANG_MODULE['blog_simple_delete_entry'] = 'blog_simple_delete_entry';
// Translation of file /home/dennis/www/coscms/modules/blog_simple/views/index.inc
// Translation of file /home/dennis/www/coscms/modules/blog_simple/model.blog_simple.inc
$_COS_LANG_MODULE['blog_simple_title'] = 'blog_simple_title';
$_COS_LANG_MODULE['blog_simple_content'] = 'blog_simple_content';
$_COS_LANG_MODULE['blog_simple_add_entry'] = 'blog_simple_add_entry';
$_COS_LANG_MODULE['blog_simple_no_title'] = 'blog_simple_no_title';
$_COS_LANG_MODULE['blog_simple_no_content'] = 'blog_simple_no_content';
$_COS_LANG_MODULE['blog_simple_add_title'] = 'blog_simple_add_title';
$_COS_LANG_MODULE['blog_simple_entry_created'] = 'blog_simple_entry_created';
$_COS_LANG_MODULE['blog_simple_view_all'] = 'blog_simple_view_all';
$_COS_LANG_MODULE['blog_simple_view_entry'] = 'blog_simple_view_entry';
$_COS_LANG_MODULE['blog_simple_update_entry'] = 'blog_simple_update_entry';
$_COS_LANG_MODULE['blog_simple_entry_updated'] = 'blog_simple_entry_updated';
$_COS_LANG_MODULE['blog_simple_entry_deleted'] = 'blog_simple_entry_deleted';
As you see it is just an array with keys that are the same as the array values. In order to translate this array we just edit the keys. My en_GB translation then looks like this when I add my human translation:
<?php
// Translation of file /home/dennis/www/coscms/modules/blog_simple/views/view.inc
$_COS_LANG_MODULE['blog_simple_written_by'] = 'Written By';
$_COS_LANG_MODULE['blog_simple_edit_entry'] = 'Edit Entry';
$_COS_LANG_MODULE['blog_simple_delete_entry'] = 'Delete Entry';
// Translation of file /home/dennis/www/coscms/modules/blog_simple/views/index.inc
// Translation of file /home/dennis/www/coscms/modules/blog_simple/model.blog_simple.inc
$_COS_LANG_MODULE['blog_simple_title'] = 'My Title';
$_COS_LANG_MODULE['blog_simple_content'] = 'Blog Content';
$_COS_LANG_MODULE['blog_simple_add_entry'] = 'Add Entry';
$_COS_LANG_MODULE['blog_simple_no_title'] = 'No Title';
$_COS_LANG_MODULE['blog_simple_no_content'] = 'No Content';
$_COS_LANG_MODULE['blog_simple_add_title'] = 'Add Entry';
$_COS_LANG_MODULE['blog_simple_entry_created'] = 'Entry Created';
$_COS_LANG_MODULE['blog_simple_view_all'] = 'View All';
$_COS_LANG_MODULE['blog_simple_view_entry'] = 'View Entry';
$_COS_LANG_MODULE['blog_simple_update_entry'] = 'Update Entry';
$_COS_LANG_MODULE['blog_simple_entry_updated'] = 'Entry Updated';
$_COS_LANG_MODULE['blog_simple_entry_deleted'] = 'Entry Deleted';
system.inc
The other file created was blog_simple/lang/en_GB/system.inc. This file contains translation that is always available. And that means our menu entries. This file looks like this:
<?php
// Translation of menu file /home/dennis/www/coscms/modules/blog_simple/menu.inc
$_COS_LANG_MODULE['blog_simple_menu_list'] = 'View All Entries';
$_COS_LANG_MODULE['blog_simple_menu_add'] = 'Add Entry';
I have translated this file into the following:
<?php
// Translation of menu file /home/dennis/www/coscms/modules/blog_simple/menu.inc
$_COS_LANG_MODULE['blog_simple_menu_list'] = 'List All Entries';
$_COS_LANG_MODULE['blog_simple_menu_add'] = 'Add Entry';
// Final: The main menu item title.
$_COS_LANG_MODULE['blog_simple_title'] = 'My Blog';
Only thing that will not be translated is the title part of the install array, and specified in the install.inc file: $_INSTALL['MAIN_MENU_ITEM']. This you will have to add yourself.
In order for the system translation to take effect we need to reload our translation for the module blog_simple. The following command reloads our system language, and it does it for all modules:
./coscli.sh install --reset
Now all system strings for all modules are reloaded. And our module should look good. That's it!
