Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
localization.py
Package: MMOPRG_server_dev.rar [view]
Upload User: ghyvgy
Upload Date: 2009-05-26
Package Size: 547k
Code Size: 2k
Category:
Other Games
Development Platform:
Python
- '''
- localization.py - demonstrates the use of lookups and contant modules to implement a solution
- for localization
- '''
- import lookup
- import constantmodule
- currentLanguage = 1
- def SetCurrentLanguage(newLanguage):
- '''
- Allows changing of language by passing one of the contants from the
- language module as the newLangauge arg
- '''
- import language
- assert language.lookup.has_key(newLanguage), 'Not a know language!'
- global currentLanguage
- currentLanguage = newLanguage
- def Lookup(localizedItemId):
- '''
- Returns the unicode text for the specified localized item, in the
- current language
- '''
- global currentLanguage
- import localizedtext
- if localizedtext.lookup.has_key((currentLanguage, localizedItemId)):
- return localizedtext.lookup[(currentLanguage, localizedItemId)][0]
- else:
- return U'Item not translated yet'
- def Test():
- '''
- Demonstrates the localization functionality, including switching
- language on the fly
- '''
- # setup the data, including unicode strings for translated text
- languageData = [ (1, 'English'), (2, 'French'), (3, 'Korean') ]
- localizedItemData = [ (1, 'Button OK'), (2, 'Button Cancel') ]
- localizedTextData = [ (1, 1, U'OK'), (1, 2, U'Cancel'), (2, 1, U'Oui'), (2, 2, U'Non')]
- # build a localizeditem contatn module and import it
- constantmodule._BuildInMemoryConstantModule('localizeditem', localizedItemData)
- import localizeditem
- # build a language constant module and a lookup, then import it
- constantmodule._BuildInMemoryConstantModule('language', languageData)
- tempDict = lookup._CreateDict(languageData)
- lookup._BuildInMemoryDictLookup('language', tempDict)
- import language
- # build a localized text lookup
- tempDict = lookup._CreateMultiWayKeyDict(localizedTextData, 2)
- lookup._BuildInMemoryDictLookup('localizedtext', tempDict)
- import localizedtext
- print'n'
- print 'Current language is %s' % language.lookup[currentLanguage]
- print 'The word for OK is %s' % Lookup(localizeditem.BUTTON_OK)
- print 'The word for Cancel is %s' % Lookup(localizeditem.BUTTON_CANCEL)
- print 'nChanging languagen'
- SetCurrentLanguage(language.FRENCH)
- print 'Current language is %s' % language.lookup[currentLanguage]
- print 'The word for OK is %s' % Lookup(localizeditem.BUTTON_OK)
- print 'The word for Cancel is %s' % Lookup(localizeditem.BUTTON_CANCEL)
- if __name__ == '__main__':
- Test()