Internationalization

Issue #191 new
youri margarin created an issue

I propose to start a translation project of the program in other languages.

  • First phase: for each file, to Identify the strings to be translated and establish correspondences between the current line number, the string and a variable to be called by the module.

  • Second phase: to make a correspondence between the same references and their translation in the French language.

  • Further, other languages may be added to the project with their own correspondence files.

Comments (33)

  1. Juan Pablo Caram repo owner

    Just some thoughts on how to go about this:

    • Create a file called FlatCAMLangEng.py

    • Import this file in FlatCAMApp.py and in FlatCAMGUI.py:

    from FlatCAMLangEng import lang
    
    • Create a single dictionary in FlatCAMLangEng.py:
    lang = {
        "menubar": {
             "file": "file",
             "fileopengerber": "Open Gerber...",
             ...
    }
    
    • Then start replacing the strings in the source code. For example, where it says "file" you would put lang["menubar"]["file"] and so on.

    • When all that is done, we need to add code to check if lang.json is in the user's settings folder. If so, we replace the lang variable imported originally with the contents of the .json file.

    • Then we write additional languages in .json files that people can download.

    Let me know what you think.

  2. youri margarin reporter

    Like that ?

    FlatCAMGUI.py (3rd line then 15th and next ones)

    from PyQt4 import QtGui, QtCore, Qt
    from GUIElements import *
    from FlatCAMLangEng import lang
    
    class FlatCAMGUI(QtGui.QMainWindow):
    
        # Emitted when persistent window geometry needs to be retained
        geom_update = QtCore.pyqtSignal(int, int, int, int, name='geomUpdate')
    
        def __init__(self, version):
            super(FlatCAMGUI, self).__init__()
    
            # Divine icon pack by Ipapun @ finicons.com
    
            ############
            ### Menu ###
            ############
            self.menu = self.menuBar()
    
            ### File ###
            self.menufile = self.menu.addMenu('lang["menubar"]["File"]')
    
            # New
            self.menufilenew = QtGui.QAction(QtGui.QIcon('share/file16.png'), 'lang["menubar"]["New"]', self)
            self.menufile.addAction(self.menufilenew)
            # Open recent
    ...etc...
    

    and:

    FlatCANLangEn.py

    lang = {
        "menubar": {
             "File": "&File",
             "New": "&New",
             "Recent": "Open recent ...",
             "OpenGerber": 'Open &Gerber ...',
             "OpenExcellon": 'Open &Excellon ...',
             "OpenG-Code": 'Open G-&Code ...',
             "Open_Project": 'Open &Project ...',
             "SVGImport": 'Import &SVG ...',
             "SaveProject": '&Save Project'
             "SaveProjectAs": 'Save Project &As ...',
    
      ...etc ...
    

    Isn't FlatCAMLangEn.py that will be translated in several languages ? What's the contents of lang.json files ?

    Regards

  3. Juan Pablo Caram repo owner

    Sorry to be tough on you, but please fix the 1st comment by properly using the "Code" formatting (I cannot edit others' comments), and delete the ones with screenshots.

  4. Juan Pablo Caram repo owner

    The English language is the default, so it has to be always present. That is why we make it part of the code. Other languages are "data", therefore they can go into data files.

    Users should not change the code, just the data. So they can add a lang.json and if FlatCAM finds it, it will read it and replace the language. We should not put English in a data file, because they are not guaranteed to exist, so if it's not found the program would crash.

    The lang.json file will look almost identical as the .py file, but in different languages.

  5. youri margarin reporter

    Done!

    I admit that I searched a while before finding the small edit bar under the message and realizing that the message needed to be save with the "comment" button ! Same style than the documentation... I'm not familiar yet with these forms.

    Your explanation sounds clear. No more questions concerning the language files.

    When I began to work on the FlatCAMGUI.py file, I noticed that there are two kinds of quotes: single and double. What's the difference ?

    After a new reading of this file, I think that I should remove the quotes before "lang" and after the second bracket otherwise they will be doubled when the strings are called. Right ?

    Last: The source files not being frozen, they may evolve in parallel to these modifications. I'm wandering how to enlighten these changes.

    • Is there a specific syntax ?

    • It might happen that some newly created strings have been introduced into files that are not yet part of the source. How to deal with that ?

    • How will the files be synchronized at the end ?

  6. Juan Pablo Caram repo owner

    It should be:

    ### File ###
    self.menufile = self.menu.addMenu(lang["menubar"]["File"])
    

    There is no difference between ' and ". You have to close the string with the same character you opened it with though. You can have one inside the other, like "youri's" or 'youri\'s'. In the last case it was necessary to escape with a \.

    Parallel work by multiple developers is the core of git, the main engine behind Bitbucket (and GitHub, etc...) It's rather complicated to learn in the beginning. The basic idea is that you "fork" the project, which results in a new "branch". You make your changes there and then we "merge" with the "master" branch. You have to take care of keeping your branch up to date. This makes it easier to merge later but it is not necessary. Git knows the order in which changes were made so it can appropriately combine changes from different developers into the same file.

    There is no way of preventing someone from explicitly introducing a literal string in English into the code. The only way is to document things well such that new contributors are aware that strings go into `FlatCAMLangEn.py'. We can somehow automate the comparison between this file and all alternate language files and alert when these have missing entries. We might need to think about this a bit further.

  7. Daniel Sallin

    Hello For me the simplest solution is to use the gettext function and have two translation file a .po and .mo in the lang directory. You will find the work already carried out in part at this address www.daniel-stp.fr/?p=549 with the French translation and the possibility of adding other language simply adding po translation files .mo and which are feasible with a tool like poEdit example. I added the ability to have characters accents. This requires adding these imports

    # For the translation by Daniel Sallin Start
    import gettext
    import os
    import sys
    unidecode import from unidecode
    pathname = os.path.dirname (sys.argv [0])
    localdir os.path.abspath = (pathname) + / Local
    gettext.install ( messages localdir)
    # Coding: utf8
    # For the translation by Daniel Sallin end
    

    and transform a sequence of character like this Original

    App.log.info ( FlatCAM Starting …”)
    

    after modification

    App.log.info (unicode ( ( FlatCAM Starting …”), utf-8))
    

    Adding _(…) is for translation Adding unicode(… .'utf-8 ') is for the character format The .po file for translation contains this

    msgid Starting FlatCAM …”
    msgid FlatCAM Demarre …”
    

    With the gettext translates what most software and interface.

  8. Juan Pablo Caram repo owner

    I just looked at the documentation for gettext. I seems this is the most common way. Would you like to work on this?

  9. Juan Pablo Caram repo owner

    Daniel, you need to submit a "pull request". You don't need any permissions for that. You do it in your own repository. Then I will receive a notification, will review your changes, and if all looks good I merge your pull request into the master.

  10. tijuca

    How to go further here? Where can I start to do some German translation? Is there a branch exists for doing translation?

  11. Juan Pablo Caram repo owner

    Hi @tijuca . There has been some work on creating the infrastructure to support multiple languages but it is not ready. So I wouldn't invest time on creating a specific translation right now. @Daniel-STP started coding the infrastructure, see pull request #51, but I havent heard from him in a while. You are totally welcome to help on this, or you can look at Daniel's code and start working on the German translation if you want.

  12. Daniel Sallin

    Hi I did not take the time to finish and add a prmlant menu to choose the desired language because I do not master Python well. The code is functional to allow for another translation. Simply add the translated .po and .mo files to the language directory.

    Daniel

  13. tijuca

    Hello @Daniel-STP , I'm also no really a Python guy so I can't help here much. I would appreciate if the current changes to the source could be applied to the current development tree. Without that it's likely no one will do further needed changes. And I would suggest to use a flatcam.po file instead of message.po.

    I can try to add some Makefile for getting automated updated po files and a gettext call for automated *.mo file creation.

  14. Juan Pablo Caram repo owner

    Someone needs to make a branch and a clean pull request. The original pull request was for the Master branch and is way behind.

  15. Daniel Sallin

    Hello I have realized the update of the development version has the version of master branch of 28.12.2016.

  16. Juan Pablo Caram repo owner

    @Daniel-STP the pull request has too many conflicts with the current version. You need to update your repository and bring it up to date.

    Also, please create a new branch. Call it "intl" or "internationalization" or something like that, in your repository, then make changes to that branch, and send a pull request from that branch. That way we can keep this work separate from the Master while it is unstable.

  17. Daniel Sallin

    I picked up the original source of that day. Modify the different files with the addition of translate _ ('Original text') in the files requiring a translation (This makes a lot of modification I agree about 1500). This is required to make FlatCam accessible to non-English speakers. The 2000 differences between our files are only translations. Thank you for going directly into the Master branch so as not to lose the day's work today. Also add in the doc here http://flatcam.org/manual/installation.html#osx this change: Now you can install all Python packages (numpy, matplotlib, rtree, scipy, shapely, simplejson, svg.path)

    thank you for your collaboration

  18. Juan Pablo Caram repo owner

    @tijuca , there is a branch with @Daniel-STP 's work on internationalization now.

  19. tijuca

    The current inclusion of gettext_windows in FlatCam.py and FlatCAMDraw.py (branch Intl) is breaking the usage of FlatCAM in Linux. This needs something like if os=Windows to ensure it's only used on a Windows system.

  20. tijuca

    I'm not using Windows normally so I can't test this, while looking at the source I was thinking the same. Right now I have to comment out the gettext_windows specific lines and FlatCAM is working again.

    And maybe the whole i18n/gettext stuff can placed in a FlatCAMi18n.py file where all the settings and setup things happen, currently it's in various files and that's a bit ugly. If this part is reworked please note that Linux/Unix systems typically place *.mo files in

    /usr/share/i18n/locales/$LANG(_$COUNTRY)/LC_MESSAGES/
    

    and FlatCAM should search there too. The $COUNTRY part is optional if the translation is using country specific variations. The desktop environments under Linux/Unix are using the language environment if set, that's almost set in recent systems. I'm not a Python programmer but I'm sure it's already read out by the Python engine. So haven't to setup something special in the GUI of FlatCAM, if the German mo file is around the GUI is shown in German.

    And please rename the *.po and *.mo files to flatcam.{mo,po}. The file name messages.* is really generic and will produce problems in the future I think.

  21. Juan Pablo Caram repo owner

    I'm getting

    ImportError: No module named unidecode
    

    Are we missing this in the setup script and dependency list?

  22. Juan Pablo Caram repo owner

    I'm not able to change the language from the menu. No errors shown at all. I'm on Ubuntu 16.04.

  23. tijuca

    Adding a German translation for FlatCAM

    I'm not willing to do fork of the flatcam tree to probably provide just one patch for months. That's to much overhead for me and not what Git was made for. Unfortunately the author isn't accepting my patch by email. So I'll add my current work here in this issue. It's rebased on the current intl branch.

    Take it or leave it. I just wanted to package FlatCAM, not to start a whole developing on it.

  24. Daniel Sallin

    tijuca: I added your German translation into the source and created the pull request in intl. thank you for your work

  25. Log in to comment