Internationalization, L10n and I18N

7

According to w3 , with regard to L10n and I18N , I have separated the explanation below that will serve as a basis to illustrate my doubts .

L10n [ source ]

  

Generally considered only as a synonym for translating a GUI or documentation, the location is substantially much more complex. It may involve customization related to:

     
  • Date, time, and number formats
  •   
  • Currency Usage
  •   
  • Checking and rating
  •   
  • Symbols, icons and colors
  •   
  • Texts and graphics that in a particular culture may be subject to misinterpretation
  •   
  • Variation of legal requirements
  •   

    I18n [ source ]

      

    Internationalization is the creation and development of a product, application or document content that allows easy localization for audiences that vary in culture, region or language.

         
  • Inclusion of support for local, regional, cultural or language preferences. Typically, this involves the pre-defined insertion of location data and features derived from available libraries or user preferences. Examples include: date and time formats, local calendars, number formats and numeric systems, list sorting and presentation, manipulation of personal names, address forms etc.
  •   

    Many examples and explanations limit internationalization only for translation of language packs and hourly and monetary formatting. Even if the i18n is used correctly, is it always related to the visual composition related to the view, displaying content formatted for the language chosen by the user?

    On location , it seems to me that in addition to maintaining a relationship with the view, it can influence controllers and models, as in examples n. 3, 5 and 6. L10n can have influence and customize the content that will be displayed - is it correct? In this case, would it also be based on the language chosen by the user or the regionalization of the content in question?

    I look for some pattern [PHP] some time but only find separate examples, and L10n is almost non-existent. My I18n provides the system translation and formatting in the view without any problems, but now I need to have management over the dynamic content according to the geolocation, and I believe it is L10n's responsibility. I do not want a multipurpose class or break standard.

        
    asked by anonymous 04.11.2014 / 21:28

    1 answer

    2
    Internationalization (i18n) is the process of developing an application that can be adapted to various types of languages without interfering with the core of the application.

    Location (l10n) : This is the process of adapting an internationalized application to a specific region or language using a specific locale and text translations. Source Wikipedia .

    In theory, the term localization (l10n) is used synonymously with internationalization (i18n), and globalization is the summary of both terms.

    For simplicity, what you want is to adapt your application to support other languages, date formats, time, and time according to the locale ) of the user, then you will use the term internationalization .

    Configuration:

    To internationalize your application with PHP, basically two aspects are important:

    01: You can set the setlocale() function according to locale defined by the user or automatically identified by your application:

    Ex:

    setlocale (LC_ALL, 'pt_BR', 'pt_BR.utf8');
    

    In this way you will change the format that the user views monetary value, date, strings and etc.

    02: Translate strings for this you will use gettext available for dozens of languages and also for PHP .

      

    NOTE: It is not effective to translate your website using arrays this causes upsetting for front-end and back-end development, as well as performance reasons.

    To use gettext you need to know if your server supports this feature:

    if (!function_exists("gettext")){
       echo "gettext não esta instalado\n";
    }
    else{
       echo "gettext é suportado\n";
    }
    

    See the PHP manual how to proceed with the installation and configuration of gettext .

    After setting up your server your application is ready to be translated. Now just proceed with the development of your application's layers (MVC) normally, but with an exception so that gettext can identify and do the translation you will now use the _() function in your strings, strings will appear, model , view or controller

    echo _("text to be translated");
    
    // ou
    
    echo gettext("text to be translated");
    

    Translation of strings

    I recommend the Poedit program to extract the strings from your application and generate your files .po ( Portable Object ) text containing your translations, an example below:

    #: test.php:3
    english/messages.po:
    msgid "Hello World!"
    msgstr "Hola Mundo"
    

    This file can be translated by anyone with the help of Poedit or another publisher. When saving this file will be compiled another file .mo Machine Object a binary file that gettext uses for reading and translation of strings .

    With your .mo translated, save to a folder according to each locale:

    Portable Object files

    .
    ├── i18n
    │   ├── en_US
    │   │   └── LC_MESSAGES
    │   │       └── messages.mo
    │   ├── en_UK
    │   │   └── LC_MESSAGES
    │   │       └── messages.mo
    │   └── es_ES
    │       └── LC_MESSAGES
    │           └── messages.mo
    └── index.php       
    

    Your texts will automatically be translated according to the user's locale.

    Considerations

    Although at first glance gettext seems to be a little complex, once configured on your system your application can be translated and updated quickly and efficiently, and it allows other people who are not programmers respectively to work in the translations of the files in a synchronous way and using only a% editor of%.

    There are some "cons" to this way to internationalize application, one of which is due to the .po binary files being stored in the server memory every change in the .mo files you will have to recompile and generate new .po files and this will restart your server.

    Alternatives if your server does not support .mo

    Alternatively you can use a similar PHP library to simulate the gettext function in the same way that WordPress uses as a fallback if there is no _() function. However, using this alternative results in a lot of server performance.

        
    30.11.2014 / 04:43