×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Strategy for supporting multiple languages

    Hi

    I would like to support additional languages in my PyS60 program (menu, messages, etc).
    Is there standard/recommended way to do this ?

    Thanks !

    Marcelo Barros

  2. #2
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: Strategy for supporting multiple languages

    Quote Originally Posted by marcelobarrosalmeida View Post
    Hi

    I would like to support additional languages in my PyS60 program (menu, messages, etc).
    Is there standard/recommended way to do this ?

    Thanks !

    Marcelo Barros
    Hi Marcelo,


    Well, there is no specific way of doing that, but I think the easiest one is saving one file for each language containing the translated strings (one string at each line)

    Then, user selects the language and you open the file and make a list with all the strings:

    Code:
    f = open('E:\\Folder\\english.lang', 'r')
    lang = f.read().split('\r\n')
    f.close()
    By the way, .lang is a cool extension to use for languages

    Sorry if it's too confusing. When I have some free time I'll try to add an example on the Wiki for this



    Hope you understood,

    Rafael.

  3. #3
    Regular Contributor
    Join Date
    Jan 2007
    Location
    Oulu, Finland
    Posts
    147

    Re: Strategy for supporting multiple languages

    I recommend using Python for this too. No need to create your own parser and you can have the power of Python to process the localizations if required.

    See Mobile Web Server's tutorial on how to do this. You can create a module for each language and simply import the correct module dynamically when the language changes.

  4. #4
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Strategy for supporting multiple languages

    Thanks GameDude\Rafael, you were cristal clear. I will try something joining both ideas !

  5. #5
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: Strategy for supporting multiple languages

    Quote Originally Posted by GameDude View Post
    I recommend using Python for this too. No need to create your own parser and you can have the power of Python to process the localizations if required.

    See Mobile Web Server's tutorial on how to do this. You can create a module for each language and simply import the correct module dynamically when the language changes.
    Aah, such beautiful code !!! Now I can add multi-language support for my sw, too I've been thinking about it, but it always slipped lower in priority list, because it was too much trouble. Now all problems are solved!

    Seriously, anyone planning to support multiple languages, please take a real good look at that code! It's well worth the effort. Maybe it's not too obvious at first look, but it will save you a lot of time, debugging and trouble later.

    Happy,

    --jouni who can't even recall previous time he woke up to see such beautiful code

  6. #6
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Cool Re: Strategy for supporting multiple languages

    Quote Originally Posted by JOM View Post
    --jouni who can't even recall previous time he woke up to see such beautiful code
    I guess, you didn't get enough time last year, to check out the Featured Articles on the Forum Nokia Wiki
    Pankaj Nathani
    www.croozeus.com

  7. #7
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: Strategy for supporting multiple languages

    Quote Originally Posted by croozeus View Post
    I guess, you didn't get enough time last year, to check out the Featured Articles on the Forum Nokia Wiki
    Wow, looks great! Ever since the Great FN UI Upgrade, I've had problems finding anything. When thinking back, I use use FN now a lot less that I used to . However that new Features Articles page looks like a real improvement! I'll have to bookmark it and check regularly

    In the meanwhile, here's some sample code about how to do text localization:

    http://jouni.miettunen.googlepages.com/localizationtest

    Cheers,

    --jouni

  8. #8
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Strategy for supporting multiple languages

    Nice demo Jouni, may I steal (with references, of course) some peaces ? ;-)

  9. #9
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: Strategy for supporting multiple languages

    Quote Originally Posted by marcelobarrosalmeida View Post
    Nice demo Jouni, may I steal (with references, of course) some peaces ? ;-)
    I would be extremely delighted about that! Feel free to use as much or little as you wish, with any modifications and completely without any references. It's ok, no problems! It was released for other people to use, not for me

    ...if you find any improvements or corrections, naturally I'd be interested If I get some energy peak, I might add support for localized graphics, pretty simple and straightforward to do. However more useful would be support for partial translations! It would require some thinking first, so I'm not going to do it any time soon. The short thinking times I can get will be used for thinking something else - unless my next app would support multiple languages, hmph

    Cheers,

    --jouni

  10. #10
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Strategy for supporting multiple languages

    Quote Originally Posted by JOM View Post

    ...if you find any improvements or corrections, naturally I'd be interested If I get some energy peak, I might add support for localized graphics, pretty simple and straightforward to do. However more useful would be support for partial translations! It would require some thinking first, so I'm not going to do it any time soon. The short thinking times I can get will be used for thinking something else - unless my next app would support multiple languages, hmph


    --jouni
    Thanks ! I am with a strategy for partial translations in my mind and I will implement it this weekend. I will give you feedback !

    See you !

  11. #11
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Strategy for supporting multiple languages

    Hi Folks,

    Using some ideas collected here, I did an implementation for multiple languages. It supports missing strings (partial translation) and use the same strategy described here by Jouni (importing modules with language stuff). Partial translation feature was based on introspection (hasattr, __dict__, __getattribute__ and __setattr__).

    Code: http://wordmobi.googlecode.com/files...ale_demo_1.zip

    Unpack and copy all files into e:\python (phone memory card). Afterwards, run wm_locale_demo.py

    For those following this thread and with Jouni code in their minds, I think only the class below is enough to understand how it works.

    Code:
    # -*- coding: utf-8 -*-
    
    __all__ = [ "Locale" ]
    
    class Loc_Data(object):
        "Translation data holder"
        pass
    
    class Default(object):
        "Default language support"
        def __init__(self):
            self.loc = Loc_Data()
            self.loc.zero = u'Zero'
            self.loc.one = u'One'
            self.loc.two = u'Two'
            self.loc.three = u'Three'
            self.loc.four = u'Four'
            self.loc.five = u'Five'
            self.loc.six = u'Six'
            self.loc.seven = u'Seven'
            self.loc.eight = u'Eight'
            self.loc.nine = u'Nine'
            self.loc.change_language = u'Change Language'
            self.loc.english_us = u'English (USA)'
            self.loc.finnish = u'Finnish'
            self.loc.hungarian = u'Hungarian'
            self.loc.portuguese_br = u'Portuguese (Brazil)'
            self.loc.about = u'About'
            self.loc.exit = u'Exit'
    
    class Locale(Default):
        "Multiple language support class"
        
        LOC_MODULE = "wm_locale_%s"
        
        def __init__(self,lang = ""):
            "Load all locale strings for one specific language or default if empty"
            
            Default.__init__(self)
            
            try:
                lang_mod = __import__( self.LOC_MODULE % ( lang ) )
            except ImportError:
                pass
            else:
                self.merge_locale(lang_mod)
    
        def merge_locale(self, lang_mod):
            "Merge new location string into default locale"
    
            # replace existing strings and keep old ones
            # if it is missing in the locale module
            for k,v in self.loc.__dict__.iteritems():
                if hasattr(lang_mod,k):
                    nv = lang_mod.__getattribute__(k)
                    self.loc.__setattr__(k,nv)

  12. #12
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: Strategy for supporting multiple languages

    Great,

    You obviously know python, unlike I! Code looks fantastic, have to check and test it carefully. If I read correctly, you do reset variables before trying to load new language == exactly what has to be done.

    Well, now I have no excuses left, my next app simply must support multiple languages

    Delighted,

    --jouni

  13. #13
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Strategy for supporting multiple languages


  14. #14
    Super Contributor
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: Strategy for supporting multiple languages

    Quote Originally Posted by marcelobarrosalmeida View Post
    Really nice example!

    Thanks for refering my name there and for one more great snippet



    Pleased,

    Rafael.

  15. #15
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Strategy for supporting multiple languages

    Quote Originally Posted by marcelobarrosalmeida View Post
    hello marcelo

    that seems to be a very interesting article. Will have a deeper look soon.

    Enjoy Pythoning
    Gaba88

Similar Threads

  1. Sending SMS in multiple languages
    By rajivjain28 in forum Mobile Java General
    Replies: 6
    Last Post: 2008-11-24, 07:57
  2. Rendering text in multiple languages
    By TheLittleBird in forum Symbian
    Replies: 0
    Last Post: 2007-06-05, 12:52
  3. Multiple languages in Carbide.C++ Developer
    By bamberro in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 3
    Last Post: 2007-04-12, 17:26
  4. Multiple languages with Carbide
    By symbianyucca in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2006-08-24, 07:15

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×