Hello,
I was trying to warp my head around LocalizableJSLink widget and instead come
up with a much simpler implementation. May be it could be included into TG,
renaming original LocalizableJSLink class into SophisticatedLocalizableJSLink
or simply CalendarLangFileLink (I like the latter because implementation seems
to be very calendar-specific).
Anyway, here is my LocalizedJSLink:
class LocalizedJSLink(JSLink):
"""
Provides a simple way to include language-specific data in your
Javascript code.
Language file to use is determined from the user's locale or from the
'language'
parameter. If there is no language file for the language (determined via
'supported_languages' parameter) than 'default_language' is used.
"""
default_language = 'en'
supported_languages = ['en']
params = ['default_language', 'language', 'supported_languages']
params_doc = {
'language' : 'language code to use ' \
'(overrides user locale setting which is the default)',
'default_language' : 'language code to use ' \
'if specified language is not supported',
'supported_languages' : 'list of supported language codes ' \
' (which means corresponding language files exist)',
}
def update_params(self, d):
super(LocalizedJSLink, self).update_params(d)
language = d.get('language') or get_locale()
if language not in self.supported_languages:
language = self.default_language
d['link'] = d['link'] % {'lang':language}
Max.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears-trunk
-~----------~----~----~----~------~----~------~--~---