Ad Widget

Collapse

zabbix 1.9.4 localization

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brian.huang
    Member
    • Jun 2011
    • 30

    #1

    zabbix 1.9.4 localization

    I understand that zabbix 1.9.4 is using gettext for localization. I reviewed the files include/locales.inc.php, and files on the directory locale, trying the understand the message:
    You are not able to choose some of the languages, because locales for them are not installed on the web server.

    What are the "flows" about how localization works? That is, what files and directories should I look and how do I make changes?
  • richlv
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Oct 2005
    • 3112

    #2
    i believe that message is a result of php gettext module evaluation and it looks at the available locales on the system (try locale -a)

    or was the question about something else ?
    Zabbix 3.0 Network Monitoring book

    Comment

    • brian.huang
      Member
      • Jun 2011
      • 30

      #3
      The message is from include/forms.inc.php

      Quote:
      // prepaitring the list of possible interface languages
      $cmbLang = new CComboBox('lang',$lang);
      $languages_unable_set = 0;
      foreach($ZBX_LOCALES as $loc_id => $loc_name){
      // checking if this locale exists in the system. The only way of doing it is to try and set one
      $locale_exists = setlocale(LC_ALL, zbx_locale_variants($loc_id)) || $loc_id == 'en_GB' ? 'yes' : 'no';

      $selected = ($loc_id == $USER_DETAILS['lang']) ? true : null;
      $cmbLang->addItem($loc_id, $loc_name, $selected, $locale_exists);

      if($locale_exists != 'yes')
      $languages_unable_set++;
      }
      // restoring original locale
      setlocale(LC_ALL, zbx_locale_variants($USER_DETAILS['lang']));

      // Numeric Locale to default
      setLocale(LC_NUMERIC, array('en','en_US','en_US.UTF-8','English_United States.1252'));

      // if some languages can't be set, showing a warning about that
      $lang_hint = $languages_unable_set > 0 ? _('You are not able to choose some of the languages, because locales for them are not installed on the web server.') : '';

      Here is my system locales:
      $ locale -a
      C
      en_US.utf8
      POSIX
      zh_TW.utf8

      The warning message is correct because there are some locales not installed. However, the combobox list doesn't show zh_TW as active or selectable. What do I need to do?

      Comment

      • richlv
        Senior Member
        Zabbix Certified Trainer
        Zabbix Certified SpecialistZabbix Certified Professional
        • Oct 2005
        • 3112

        #4
        but there is no zh_TW translation in zabbix. yet
        Zabbix 3.0 Network Monitoring book

        Comment

        • brian.huang
          Member
          • Jun 2011
          • 30

          #5
          zh_TW

          That is what I am going to do.
          But, I need to know how to do localization first!

          Comment

          • richlv
            Senior Member
            Zabbix Certified Trainer
            Zabbix Certified SpecialistZabbix Certified Professional
            • Oct 2005
            • 3112

            #6
            awesome.

            for Zabbix 2.0 gettext will be used. if you have worked with gettext tools before, you may consider using them for offline translation.

            if not, there is a pootle instance set up where you can translate zabbix online within your web browser. see http://www.zabbix.com/documentation/...d_localisation for some initial instructions - if anything's unclear, questions always welcome in #zabbix on freenode.
            Zabbix 3.0 Network Monitoring book

            Comment

            • richlv
              Senior Member
              Zabbix Certified Trainer
              Zabbix Certified SpecialistZabbix Certified Professional
              • Oct 2005
              • 3112

              #7
              just to let you know that zh_TW has been added at https://www.zabbix.org/pootle/projects/Zabbix-2.0/ - it has no strings translated yet, though
              Zabbix 3.0 Network Monitoring book

              Comment

              • brian.huang
                Member
                • Jun 2011
                • 30

                #8
                I was busy on another project until last week. I finally found time to solve my problem by actually studying the codes. Since I compiled the PHP stack as a standalone package from sources on Ubuntu, the gettext was not correctly linked because Ubuntu doesn't default gettext to /use/local/gettext. Therefore, the real problem is because gettext is not functional in my system. I rebuild PHP with the parameter --with-gettext=<custom directory> and it worked.

                Although I never did PHP before, I read the codes and figure out how to add zh_TW locale.

                1. add the locale zh_TW to the function set_zbx_locales() in the file <zabbix>/include/locales.inc.php.
                2. add the corresponding locale variable to the file <zabbix>/include/locales/en_gb.inc.php as
                'S_CHINESE_TW'=> _('Chinese (TW)'),
                3. on Ubuntu, add the locale zh_TW.UTF-8
                $ sudo locale-gen zh_TW.UTF-8
                4. do the translation inside the directory <zabbix>/locale/
                (4.1)generate frontend.pot. There is no file frontend.pot at the first place but step 4.2 needs the file frontend.pot.
                $ ./update_po.sh
                (4.2) add a new language:
                $ ./add_new_language.sh zh_TW
                svn: '.' is not a working copy
                svn: 'zh_TW/LC_MESSAGES' is not a working copy
                po template frontend.pot missing
                {I have no idea about why the above error occurred. But ignore it.}
                (4.3)Simply uses frontend.po from zh_CN:
                $ cp zh_CN/LC_MESSAGES/frontend.po zh_TW/LC_MESSAGES/frontend.po
                (4.4) translate from zh_CN to zh_TW.
                (4.5)run update_po.sh again.
                $ ./update_po.sh
                (4.6)generate mo file, I didn't use the script make_mo.sh which is problematic in my case.
                $ msgfmt zh_TW/LC_MESSAGES/frontend.po -o zh_TW/LC_MESSAGES/frontend.mo
                (4.7) do steps 4.4 thru 4.6 until all strings are translated.

                Here is how I make zh_TW works. I will translate the po file this week. Can I just contribute the file back to zabbix?

                Zabbix is great and promising. But PHP has too many dependencies on other libraries although I managed to make PHP stack a standalone package which requies absolutely no installation. That is, all dependencies are included and statically linked. I am still considering writing an admin UI in Java using Vaadin.

                By the way, could the honorable Zabbix designers please modify the files <zabbix>/include/locales.inc.php and <zabbix>/include/locales/en_gb.inc.php to make zh_TW work by default in the next release?

                Comment

                • richlv
                  Senior Member
                  Zabbix Certified Trainer
                  Zabbix Certified SpecialistZabbix Certified Professional
                  • Oct 2005
                  • 3112

                  #9
                  not sure why you didn't install php from distribution packages.
                  anyway, you may use either pootle or standalone tools - if using standalone tools, just create a zbxnext issue in zabbix issue tracker and attach the po to it, thanks.
                  Zabbix 3.0 Network Monitoring book

                  Comment

                  • brian.huang
                    Member
                    • Jun 2011
                    • 30

                    #10
                    Thanks for the reply.

                    the font DejaVuSans.ttf doesn't support Chinese and I have to swap it with a unicode font which can support CJK (Chinese, Japanese, Korean). Is it possible to add a combobox for the user to select the correct font for the selected locale?

                    Comment

                    • richlv
                      Senior Member
                      Zabbix Certified Trainer
                      Zabbix Certified SpecialistZabbix Certified Professional
                      • Oct 2005
                      • 3112

                      #11
                      while currently users indeed have to replace the font manually, translations can be added anyway. but you could create a new feature request for font selection at https://support.zabbix.com
                      Zabbix 3.0 Network Monitoring book

                      Comment

                      • brian.huang
                        Member
                        • Jun 2011
                        • 30

                        #12
                        I figured out a way to automatically swap fonts without requesting a new feature. Would you consider this solution? Since I am a PHP newbie, I don't know if this is ok but it works. You are welcome to take my idea and do it in a better way.

                        First, I added a function setFontnames() into the file include/locales.inc.php as followed.

                        function setFontnames(){
                        global $USER_DETAILS;
                        $ZBX_FONT_NAME = $USER_DETAILS['lang'];
                        $ZBX_GRAPH_FONT_NAME = $USER_DETAILS['lang'];
                        }

                        In the directory fonts, I added some Unicode fonts and added soft links:
                        i.e.
                        $ ln -s DejaVuSans.ttf en_GB.ttf
                        $ ln -s bsmi00lp.ttf zh_CN.ttf
                        $ ln -s uming.ttc zh_TW.ttf
                        ....

                        Finally, I called setFontnames() in the file include/graphs.inc.php at the beginning of each of the following functions:

                        function imageText($image, $fontsize, $angle, $x, $y, $color, $string){
                        setFontnames();
                        ...
                        }

                        function imageTextSize($fontsize, $angle, $string){
                        setFontnames();
                        ...
                        }
                        Last edited by brian.huang; 07-07-2011, 04:13.

                        Comment

                        • richlv
                          Senior Member
                          Zabbix Certified Trainer
                          Zabbix Certified SpecialistZabbix Certified Professional
                          • Oct 2005
                          • 3112

                          #13
                          that's an interesting approach, but it would still have to be discussed - if you'd like for it to go upstream, please submit an issue in the tracker
                          Zabbix 3.0 Network Monitoring book

                          Comment

                          • brian.huang
                            Member
                            • Jun 2011
                            • 30

                            #14
                            Thanks. I am creating an issue now.

                            It would be better to change the font name whenever a user's language has been changed. I tried to search for the exact file but got confused. Could you please point out which file is used to save the language setting to the database?

                            Comment

                            • brian.huang
                              Member
                              • Jun 2011
                              • 30

                              #15
                              An issuse has been created here: https://support.zabbix.com/browse/ZBX-3927

                              Comment

                              Working...