Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
wiki:documentation:devguide:core:translator [2016/10/04 08:33] carolina.santos [C++] |
wiki:documentation:devguide:core:translator [2016/11/04 07:32] (current) carolina.santos [CMake] |
||
---|---|---|---|
Line 7: | Line 7: | ||
Translation dictionaries are sets of textual and binary files that are created through the [[https://www.gnu.org/software/gettext/ | GNU Gettext]] tools. | Translation dictionaries are sets of textual and binary files that are created through the [[https://www.gnu.org/software/gettext/ | GNU Gettext]] tools. | ||
- | The translation is not automatic, it is necessary to perform this process manually in the files "po". | + | The translation is not automatic, it is necessary to perform this process manually in the "po" files. |
===== API ===== | ===== API ===== | ||
Line 24: | Line 24: | ||
\brief This singleton is designed to deal with multi-language text translation in TerraLib. | \brief This singleton is designed to deal with multi-language text translation in TerraLib. | ||
*/ | */ | ||
- | class TECOREEXPORT Translator | + | class Translator |
{ | { | ||
Line 156: | Line 156: | ||
==== CMake ==== | ==== CMake ==== | ||
- | Para facilitar a criação de arquivos binários contendo as mensagens traduzidas, bem como sua inclusão nos pacotes de distribuição binária dos aplicativos da família TerraLib, foi criada uma macro no CMake chamada **TERRALIB_REGISTER_TRANSLATION** capaz de automatizar esse processo. Esta macro encontra-se no arquivo //build/cmake/terralib_macros.cmake// do repositório de código. | + | To facilitate the creation of binary files containing the translated messages as well as their inclusion in the binary distribution of packages in TerraLib family applications, the macro **TERRALIB_REGISTER_TRANSLATION** was created in CMake to be able to automate this process. This macro is in //build/cmake/terralib_macros.cmake// file in the code repository. |
- | Todas as bibliotecas da TerraLib que necessitarem do sistema de tradução de mensagens deverão usar a macro acima em seus arquivos de projeto de build (//CMakeLists.txt//). Ela possui a seguinte forma: | + | All TerraLib libraries that need the message translation system should use the above macro in their build project files (//CMakeLists.txt//), in the following form: |
<code cpp> | <code cpp> | ||
- | TERRALIB_REGISTER_TRANSLATION("nome-biblioteca" "idioma" "diretório-arquivo-po" "diretório-saída-arquivo-mo") | + | TERRALIB_REGISTER_TRANSLATION("library-name" "language" "po-file-directory" "mo-file-output-directory") |
</code> | </code> | ||
- | Onde: | + | Where: |
- | * ''nome-biblioteca'': nome da biblioteca ou executável definido como target no script CMake. Ex: terralib_mod_core | + | * ''library-name'': library name or executable set to target in CMake script. Ex: terralib_mod_core |
- | * ''idioma'': região que se encontram as traduções. Ex: pt_BR | + | * ''language'': region of translations. Ex: pt_BR |
- | * ''diretório-arquivo-po'': pasta onde se encontra o arquivo de traduções. O arquivo nesta pasta deve obedecer a seguinte regra de formação: //nome_da_biblioteca_idioma//. Ex: terralib_mod_core_pt_BR.po | + | * ''po-file-directory'': folder of the translation file. The file in this folder must meet the following formation rule: //library_name_language//. Ex: terralib_mod_core_pt_BR.po |
- | * ''diretório-saída-arquivo-mo'': pasta de saída para o arquivo binário gerado a partir do arquivo contendo as traduções. De preferência, utilize uma pasta na árvore de build do projeto CMake. Ex: ${CMAKE_BINARY_DIR}/share/terralib/translations | + | * ''mo-file-output-directory'': output folder to the binary file generated from the file containing the translations. Preferably, use a folder in the build tree of CMake project. Ex: ${CMAKE_BINARY_DIR}/share/terralib/translations |
- | Como exemplo, vamos tomar a linha do arquivo //CMakeLists.txt// do projeto da biblioteca TerraLib.Core: | + | As an example, we can take the line of //CMakeLists.txt// file of the TerraLib.Core project library: |
<code cpp> | <code cpp> | ||
Line 180: | Line 180: | ||
- | ===== Exemplos ===== | + | ===== Examples ===== |
- | Os arquivos ".po" podem ser criados na linha de comando com as ferramentas da [[https://www.gnu.org/software/gettext/ | GNU Gettext]] ou através de ferramentas gráficas como o [[https://poeditor.com/ | POEditor]] ou o [[https://poedit.net/download | Poedit]]. | + | The files ".po" can be created from the command line with the tools of [[https://www.gnu.org/software/gettext/ | GNU Gettext]] or through graphical tools like [[https://poeditor.com/ | POEditor]] or [[https://poedit.net/download | Poedit]]. |
- | A seguir, iremos mostrar como criar esses arquivos na linha de comando com as ferramentas da [[https://www.gnu.org/software/gettext/ | GNU Gettext]]. | + | Next, we will show how to create these files on the command line with [[https://www.gnu.org/software/gettext/ | GNU Gettext]] tools. |
- | Para começar um novo arquivo de tradução, primeiramente, temos que criar um arquivo com a extensão ".pot", que conterá um template das mensagens identificadas no código fonte. O comando a seguir mostra como extrair as mensagens dos arquivos informados: | + | To start a new translation file, first we have to create a file with the extension ".pot", which contains a template of the messages identified in the source code. The following command shows how to extract messages from the reported files: |
<code cpp> | <code cpp> | ||
Line 192: | Line 192: | ||
</code> | </code> | ||
- | O comando acima irá produzir o arquivo //terralib_unittest_core.pot//. | + | The above command will produce the file //terralib_unittest_core.pot//. |
- | Caso você ainda não tenha um arquivo com a extensão ".po", no caso da criação de novas bibliotecas, utilize o comando abaixo para criar este arquivo onde deverão ser incluídas as traduções para um determinado idioma: | + | If you do not already have a file with the extension ".po" in the case of creating new libraries, use the following command to create this file where should be included the translations for a particular language: |
<code cpp> | <code cpp> | ||
Line 200: | Line 200: | ||
</code> | </code> | ||
- | O comando acima irá produzir o arquivo //terralib_unittest_core_pt_BR.po//. | + | The above command will produce the file //terralib_unittest_core_pt_BR.po//. |
- | Caso você já possua um arquivo ".po" e deseje apenas realizar uma atualização do mesmo, você pode fazer isso através do seguinte comando: | + | If you already have a file ".po" and just want to perform an update, you can do this using the following command: |
<code cpp> | <code cpp> | ||
Line 210: | Line 210: | ||
</code> | </code> | ||
- | **Nota:** No comando xgettext, onde você está atualizando o arquivo template, você pode informar novos arquivos se necessário. | + | **Note:** In xgettext command where you are upgrading the template file, you can enter new files if necessary. |
- | A criação dos arquivo binários com a extensão ".mo", contendo as traduções para uso nos sistemas, é feita de forma automática no build através da macro **TERRALIB_REGISTER_TRANSLATION**. Para isso, acrescente no seu //CMakeLists.txt// o registro de traduções como mostrado abaixo: | + | The creation of the binary files with the extension ".mo", containing translations to use in the systems, is done automatically in the build through the macro **TERRALIB_REGISTER_TRANSLATION**. Add to your //CMakeLists.txt// the record of translations as shown below: |
<code cpp> | <code cpp> | ||
Line 220: | Line 220: | ||
</code> | </code> | ||
- | **Nota:** utilizar o mesmo nome da biblioteca ou executável no registro de sua tradução. | + | **Note:** use the same name as the library or executable in the record of your translation. |
- | No seu código fonte inclua uma chamada à macro **TE_ADD_TEXT_DOMAIN** para adicionar em tempo de execução o seu arquivo de tradução. Veja o exemplo abaixo: | + | In your source code include a call to the macro **TE_ADD_TEXT_DOMAIN** to add at runtime your translation file. See the example below: |
<code cpp> | <code cpp> | ||
Line 244: | Line 244: | ||
</code> | </code> | ||
- | Uma vez que o arquivo de tradução encontra-se carregado, as macros **TE_TR** e **TE_TR_PLURAL** irão produzir a tradução correta: | + | Once the translation file is loaded, macros **TE_TR** and **TE_TR_PLURAL** will produce the correct translation: |
<code cpp> | <code cpp> | ||
Line 275: | Line 275: | ||
- | ===== Referências ===== | + | ===== Additional References ===== |
* [[http://www.boost.org/doc/libs/1_56_0/libs/locale/doc/html/messages_formatting.html | Boost.Locale - Messages Formatting (Translation)]] | * [[http://www.boost.org/doc/libs/1_56_0/libs/locale/doc/html/messages_formatting.html | Boost.Locale - Messages Formatting (Translation)]] |