如何进一步汉化FreePBX界面
Translating FreePBX Manually
FreePBX began including the gettext package for i18n since version 2.5. This makes translating (localization) to your desired language relatively simple using the following steps:
Translation files
In each modules/<modulename>/i18n directory there is a <modulename>.pot file. This is a template file with all the strings needed for translation. Create a new language directory structure in the i18n directory and copy the <modulename>.pot file to lang_code/LC_MESSAGES/<modulename>.po Replace lang_code with the proper language code for your translation (hint: see /usr/share/locale/locale.alias).
Note: core does not contain an i18n directory as all text for core is located in admin/i18n/lang_code/LC_MESSAGES/amp.po - amp.mo and the template file are in admin/i18n.
Example
You want to translate the backup module to Danish, First check the language code for Danish in locale.alias. For Danish it is da_DK, then create the directory structure (backup/i18n/da_DK/LC_MESSAGES), then copy the i18n/backup.pot to da_DK/LC_MESSAGES/backup.po.
Translating the File
Continuing from our above example, in backup.po you will see several "msgid" and "msgstr" name/value pairs. "msgid" contains the string to be translated and "msgstr" will be where you put your translation for the given "msgid". Here's an example from the core module where we translate "Delete Route %s" to Spanish:
#: amp_conf/htdocs/admin/modules/core/page.routing.php:275
#: amp_conf/htdocs/admin/modules/core/page.did.php:141
#, php-format
msgid "Delete Route %s"
msgstr "Agregar Usuario %s"
If you are working in Linux there is a PO-editor called KBabel which you may prefer to use. Otherwise you may also want to check out the cross-platform (Linux/Mac/Windows) editor called Poedit.
Compiling your translation file
The .po file needs to be compiled into an .mo file before it can be used. To do this, run:
Note: If you are using KBabel or Poedit, the files are compiled with these programs and you don't have to do the next part
msgfmt -v <module>.po -o <module>.mo
For example, you have translated the backup.po, to compile it, run:
msgfmt -v backup.po -o backup.mo
You might have some errors to correct, which are usually a result of quoting problems or that you have not updated the header in the .po file. If you have no error and all is good, continue to the next step.
Testing your Translation
To see your translations at work, you need to update FreePBX's code to include your translation. The file that you'll need to edit is located at /var/www/html/admin/views/menu.php (on a default CentOS install), and you'll want to look for the code block shown below:
/var/www/html/admin/views/menu.php
if($amp_conf['SHOWLANGUAGE']) {
$out .= '<a id="language-menu-button" '
. 'class="button-right ui-widget-content ui-state-default">' . _('Language') . '</a>';
$out .= '<ul id="fpbx_lang" style="display:none;">';
$out .= '<li data-lang="en_US"><a href="#">'. _('English') . '</a></li>';
$out .= '<li data-lang="bg_BG"><a href="#">' . _('Bulgarian') . '</a></li>';
$out .= '<li data-lang="zh_CN"><a href="#">' . _('Chinese') . '</a></li>';
$out .= '<li data-lang="de_DE"><a href="#">' . _('German') . '</a></li>';
$out .= '<li data-lang="fr_FR"><a href="#">' . _('French') . '</a></li>';
$out .= '<li data-lang="he_IL"><a href="#">' . _('Hebrew') . '</a></li>';
$out .= '<li data-lang="hu_HU"><a href="#">' . _('Hungarian') . '</a></li>';
$out .= '<li data-lang="it_IT"><a href="#">' . _('Italian') . '</a></li>';
$out .= '<li data-lang="pt_PT"><a href="#">' . _('Portuguese') . '</a></li>';
$out .= '<li data-lang="pt_BR"><a href="#">' . _('Portuguese (Brasil)') . '</a></li>';
$out .= '<li data-lang="ru_RU"><a href="#">' . _('Russian') . '</a></li>';
$out .= '<li data-lang="sv_SE"><a href="#">' . _('Swedish') . '</a></li>';
$out .= '<li data-lang="es_ES"><a href="#">' . _('Spanish') . '</a></li>';
$out .= '</ul>';
}
Once you've located the code block, you'll want to add you code to above the line that shows:
$out .= '</ul>';
For example, if you want to add Danish as the new language, you would add the following live above the code block above:
$out .= '<li data-lang="da_DK"><a href="#">' . _('Danish') . '</a></li>';
Finally you can test your translations by refreshing your browser window and selecting your new language. If everything looks good, zip up your translated <modules>.po and <modules.>mo files and submit them by creating a New Ticket in our bug tracker. For information on how to do that, please see [file:///E:/display/FOP/Bug+Reporting Bug Reporting].
Determining Translation Status
The languagestatus module provides developers insight into the translation status of core modules. To install the module, follow the steps below:
- Click Admin
- Choose Module Admin
- Make sure Unsupported is checked
- Check for Updates
- Install languagestatus
The module provides a menu option under Admin called Language Status. If you click on this, you will be greeted with a page that tells you to choose a language. If you do not have the language selection dropdown in the menu, complete the following:
- Click Settings
- Choose Advanced Settings
- Set Show Language setting to True
Choose a language other than English to see how well core modules are translated.