Ticket #1086 (closed defect: fixed)

Opened 1 year ago

Last modified 11 months ago

Get localization framework in place and working

Reported by: paul Assigned to: somebody
Priority: critical Milestone: 1.0
Component: ui Version: 0.9.x
Keywords: Cc:

Description

We need the mechanism for creating .po files, editing existing .po files, and compiling the .mo files to be in place, for several languages, including Spanish, Italian, German, and Russian.

Ed did a great deal if not all of this in [3262] and [3263], and Paul and Uwe followed up with minor additions in [3265], [3267], and [3268].

We obviously need to fill in the translations, which if I understand correctly will happen somewhat automatically thanks to the service at Canonical. See:

http://leafe.com/archives/byMID/dabo-dev/D95464FD-2B56-4C69-B5E2-820382D108FF@leafe.com

I just wanted to get this ticket added to the 1.0 milestone, as it wasn't there yet (could have sworn we had a ticket already).

Attachments

dLocalize.py (2.7 kB) - added by shawkat@samdu.uz on 07/23/07 21:43:36.
dLocalize.py
dLocalize.2.py (3.6 kB) - added by shawkat@samdu.uz on 07/23/07 23:36:33.
tried to deal with tabs/spaces, some comments, some kind of testing
dLocalize.3.py (3.9 kB) - added by paul on 07/24/07 23:11:52.
paul's version
dLocalize.4.py (5.1 kB) - added by shawkat@samdu.uz on 07/25/07 05:25:02.

Change History

07/20/07 15:19:25 changed by nate

Would it be worth writing a GUI tool to make this easier?

Great job on this Ed.

07/20/07 17:42:35 changed by paul

A question I have is: where does localization of a given dabo-based application happen? Where does the application developer put their .mo files so that Dabo will find them and translate the strings at runtime?

07/20/07 18:13:48 changed by nate

I don't think that it has come up yet. I was under the assumption that the localization was just for strings appearing in the framework and if the developer required multiple languages he would have to roll his own system.

However, I think that your question definitely has merit. I think that it would be a nice feature for the framework. I would suggest coding a method that takes a directory path to a locale directory. That way the developer can implement their preferred directory structure. The structure inside the locale directory should mimic the structure of the dabo locale directory.

07/23/07 21:43:36 changed by shawkat@samdu.uz

  • attachment dLocalize.py added.

dLocalize.py

07/23/07 21:44:47 changed by shawkat@samdu.uz

I did a major rewrite of dLocalize.py, because 1) current version doesn't support localization of user app, only the framework 2) supported localizations are hardcoded 3) there were several bugs

My approach is that as soon as we do "from dLocalize import _" we get the dabo framework localized (locale is taken from environment). From this point we can use localization in framework itself, but non in application yet. If localization for current locale is not available, we just fall back to english. So only english dabo.mo is a must. You can add any other localizations to dabo's localedir

After user application initialization we try also to support its own localizations. They are searched in app's locale directory. Now we have two localizations inplace - translatable string is searched in app's localization (reside under app's locale dir), if not found we try to find it in dabo's localization (reside in dabo's locale dir). So both framework and app are localized with their owns, and both work simultaniously.

good sideffects: 1) we dont' have to translate app's strings if they are already in dabo's localization 2) strings in app's localization override dabo's

current limitations (i will work on them): 1) don't know how to handle situations when either dabo or app is missing its localization. 2) on-the-fly localization's change ? 3) user app's localization is in "app.mo" file, while it should to be in "appname.mo" 4) system wide locale directories are not searched

following is the quick check, that i did and it worked :)

from dLocalize import _ #framework itself is localized at this moment #so we can have diagnostik messages of framework to be localized

import dabo

# but application is still not !

app = dabo.dApp()

app.setup()

# now we can have app's localization

print _('application localization test') # works here, russian string is printed

form = dabo.ui.dForm(app.MainForm?, Caption=_("Hello!")) # works here, windows' title is in russian

tb = form.addObject(dabo.ui.dTextBox, "tbox")

tb.Value = "Cool stuff!" # But if i try here, i get an error: UnicodeDecodeError?: 'ascii' codec can't decode byte 0xcf # in position 13: ordinal not in range(128)

form.tbox.FontBold? = True

form.Visible = True

app.start()

07/23/07 21:55:46 changed by paul

Great, thanks! I'm going to let Ed review this, since he's done most of the localization stuff. +1 from me, though, from the looks of it.

07/23/07 22:20:07 changed by paul

Oops, please convert to tab indentation and resubmit. Also, it would be great if you would be consistent:

__localedir = "locale"
__dabo_trans=None

We like a space before and after the = in assignments, like you did localedir.

Thanks! :)

07/23/07 23:36:33 changed by shawkat@samdu.uz

  • attachment dLocalize.2.py added.

tried to deal with tabs/spaces, some comments, some kind of testing

07/24/07 11:20:25 changed by uwe_grauer

From http://babel.edgewall.org/

Babel
A collection of tools for internationalizing Python applications

Babel is composed of two major parts:

    * tools to build and work with gettext message catalogs
    * a Python interface to the CLDR (Common Locale Data Repository), providing access to various locale display names, localized number and date formatting, etc. 

07/24/07 23:11:52 changed by paul

  • attachment dLocalize.3.py added.

paul's version

07/24/07 23:13:43 changed by paul

I took dLocalize.2.py, and modified it to not require the app's locale structure to be set up, and to take into account my changes from last night that make it work in frozen apps. Please review on your end and let me know if it still works for you.

Thanks!

07/25/07 05:25:02 changed by shawkat@samdu.uz

  • attachment dLocalize.4.py added.

07/25/07 05:32:12 changed by anonymous

Now it works as expected: user app's localization is used, if it actually exist I performed some tests - works for me

Don't know what to do with that hack, overcoming python string 7-bitness

07/27/07 14:38:26 changed by paul

See dabo revision [3286] - I believe we just about have this licked. Thanks, Nizamov!

07/30/07 13:27:26 changed by paul

  • status changed from new to closed.
  • resolution set to fixed.

I think that overcoming the default ascii encoding should be left to the user/application developer. But yes, we should document it somewhere, perhaps in the FAQ?

09/28/07 02:29:47 changed by Hraban

  • status changed from closed to reopened.
  • type changed from task to defect.
  • version set to 0.9.x.
  • resolution deleted.

Small typo in dLocalize.py / getLocaleDir: there's once "localeDir" (uppercase D) that leads to "NameError?: global name 'localeDir' is not defined" with py2app/py2exe.

def getDaboLocaleDir():
	localedir = os.path.join(os.path.split(dabo.__file__)[0], "locale")
	if not os.path.isdir(localedir):
		# Frozen app?
		# First need to find the directory that contains the .exe:
		startupDir = localedir
		while startupDir:
			startupDir = os.path.split(startupDir)[0]
			if os.path.isdir(startupDir):
				break
		localedir = os.path.join(startupDir, "dabo.locale")
	return localedir

09/28/07 07:36:51 changed by paul

  • status changed from reopened to closed.
  • resolution set to fixed.

Fixed in [3411]. Thanks!