473,795 Members | 2,929 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing an applilcation that can easily adapt to any language

I am rather new at Python so I want to get it right. What I am doing
is writing a rather large application with plenty of places that
strings will be used. Most of the strings involve statements of
one kind or another.

I would like to make it easy for the support people to port the
application from one language to another, German, Spanish, etc.
Rather than make them search all over for the strings to replace
is there a library that I can use to make this all easier? I
keep thinking of resources in Java, as an example. Is there
anything like it in Python?

Peace,
Chance.
Mar 1 '06 #1
2 1176
Chance Ginger wrote:
I am rather new at Python so I want to get it right. What I am doing
is writing a rather large application with plenty of places that
strings will be used. Most of the strings involve statements of
one kind or another. I would like to make it easy for the support people to port the
application from one language to another, German, Spanish, etc.
Rather than make them search all over for the strings to replace
is there a library that I can use to make this all easier? I
keep thinking of resources in Java, as an example. Is there
anything like it in Python?


http://www.python.org/doc/2.4.2/lib/module-gettext.html

HTH
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom. gro'.split('@')])"
Mar 1 '06 #2
Chance Ginger wrote:
I am rather new at Python so I want to get it right. What I am doing
is writing a rather large application with plenty of places that
strings will be used. Most of the strings involve statements of
one kind or another.

I would like to make it easy for the support people to port the
application from one language to another, German, Spanish, etc.
Rather than make them search all over for the strings to replace
is there a library that I can use to make this all easier? I
keep thinking of resources in Java, as an example. Is there
anything like it in Python?


Brono's suggestion is most certainly very good. If you are looking for
something more light-weight, you might enjoy my module language that I
include below. The idea is to have everything language-specific in one
module, that is imported everywhere it is needed in my application. Consider

import language
fileText = language.texts['file']

After this, fileText is either 'File' or 'Arkiv' depending on if
language.lang is 'en' or 'sv'. The docstrings should be enough
documentation to use the module. perhaps you might want to split the
module up into two modules, one containing the class, and one containing
the texts.

/MiO

And here is the module:

# -*- coding: cp1252 -*-

"""Module language:
The most important object made available here is the following:

handleLanguage
A class that handles information in different languages. See the
doc-string of this class for more information.

texts
A dictionary containing objects of the class handleLanguage.

lang
A string representing chosen language.

availableLangua ges
A list of strings representing available languages. The first
item is the default fallback language if lang fails.

"""

lang='en'
availableLangua ges=[lang]
class handleLanguage( dict):
"""class handleLanguage:
A class that handles information in different languages as strings.
This class is instantiated as follows:

foo=handleLangu age(sv='blah',e n='blahblah')

After that we have foo['sv']=='blah' and foo['en']=='blahblah'.
Also, the languages 'sv' and 'en' will have been appended to the
module level list availableLangua ges if they were not in that list
before.

Now let foo be any instance of this class. The real funtionality of
this class is that str(foo) depends on the module variables lang and
availableLangua ges. More precicely str(foo)==foo[x] where x chosen
according to the following.

if lang in foo: x=lang
elif availableLangua ges[0] in foo: x=availableLang uages[0]
elif 'en' in foo: x='en'
else: x=foo.keys()[0].

If none of this works, then we have str(foo)=='??', which only
happens if foo does not contain any language.
"""
def __init__(self,* *kwargs):
dict.__init__(s elf,**kwargs)
for key in kwargs:
if key not in availableLangua ges:
availableLangua ges.append(key)
def __str__(self):
try:
return self[lang]
except KeyError:
if availableLangag es[0] in self:
return self[availableLangag es[0]]
elif 'en' in self:
return self['en']
elif self:
return self[self.keys()[0]]
else:
return '??'
def __add__(self,ot her):
if not isinstance(othe r,dict):
foo,other=self. __coerce__(othe r)
new=handleLangu age(**dict(othe r))
new.update(self )
for key in self:
if key in other:
new[key]=self[key]+other[key]
return new
def __radd__(self,o ther):
if not isinstance(othe r,dict):
foo,other=self. __coerce__(othe r)
new=handleLangu age(**dict(othe r))
new.update(self )
for key in self:
if key in other:
new[key]=other[key]+self[key]
return new
def __coerce__(self ,other):
new=handleLangu age()
for key in self:
new[key]=str(other)
return self,new

texts={
# Common texts
'appName':handl eLanguage(
sv='Uppgiftshan teraren',
en='TaskManager ',
),
'foo':handleLan guage(
sv='foo',
en='foo',
),
# File menu
'file':handleLa nguage(
sv='Arkiv',
en='File',
),
'help':handleLa nguage(
sv='Hjälp',
en='Help',
),
'open':handleLa nguage(
sv='Öppna',
en='Open',
),
}

if __name__=="__ma in__":
keys=texts.keys ()
keys.sort()
for lang in availableLangua ges:
print lang
for key in keys:
print ' ',key+':',texts[key]
print
print 'Done'
Mar 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1784
by: mark1822 | last post by:
Hi, I am trying to figure out if I should learn C and C++ to write CGI programs, or if I should just use PHP for my web site. I want to write a high traffic website that would call executibles a lot dealing with text. Are CGI programs written in C faster then PHP script programs?
40
4283
by: post400 | last post by:
Hi, there is another famous book 'Writing solid code' but does it apply to Python ? Or it's usable only by Microsoft C programmers ? The author seems to be an ex-Microsoft guy ! Thanks , post400
385
17322
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like extraneous jargons, such as in the Unix & Perl community. Unlike mathematicians, where in mathematics there are no fewer jargons but each and every one are
6
3502
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being written. /* Book name : File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp Program discription: Adding name,Address to customer_record SETUP PROGRAM
9
2939
by: 100 | last post by:
Has anybody read Steve Maguire's book "Writing solid code"? Do you think that the ideas in this book are not applicable in c# language? Does anybody find if(2 == i) istead of if(i == 2) as unnetural and does it lead to more bugs in the code because of it makes programms hard to read. And my last question is: "Do you think that using boolean expressions
19
2544
by: Marco | last post by:
FYI: Guidelines for writing efficient C/C++ code http://www.embedded.com/showArticle.jhtml?articleID=184417272 any comments?
2
3950
by: Gustaf | last post by:
I read some data from an XML file. Some datas need to be converted to decimals. The program is to be used in any country, so sometimes the decimal sign is "." and sometimes ",". How can I make Convert.ToDecimal() adapt to the user's language settings? Assume Windows XP and .NET Framework 1.1. Gustaf
7
5558
by: Matt Kowalczyk | last post by:
Hello, I am working on a compression project and I want to write ASCII characters using the minimum amount of bits. Since I will be writing ASCII characters from 0-127 I only need 7 bits to represent a character. Therefore, if I write each character at a time, I will end up writing 8 bits. One method would be to somehow concatinate all the 7 bit words I am trying to write and just pad the last byte.
0
2182
by: mcc99 | last post by:
Amazing, I surfed around to find a simple utility that could list files recursively from a given top folder down through it, writing out the path and filename in simple \path\file_name form, without writing out empty folder names, if any. Well I found a couple utilities but they all tried to do all this other stuff, do it in Excel with no copy and paste, etc. Not a one that just writes a simple text file with the path and file name. So I...
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10448
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.