Hi Max,

I was thinking in this subject 2 weeks ago...

My situation: systems developed for Brazilian people must have dates
in dd/mm/yyyy format... But there are many people (read *me*) who
likes to use SO and browsers with English language... that helps
finding solutions to errors that appear during development cycle
live... English is the universal language in Internet...

So, I was thinking in tweaking LocalizableJSLink in order to have
something like "PreferedLanguage / PreferedCharset"...
This is a *not-tested* modification:


class LocalizableJSLink(JSLink):
    prefered_language = None
    prefered_charset = None

    def update_params(self, d):
        accept_language = parse_http_accept_header(
            request.headers.get("Accept-Language")
        ) or ['']
        accept_charset = parse_http_accept_header(
            request.headers.get("Accept-Charset")
        ) or ['']

        if prefered_language:
            accept_language = prefered_language + accept_language
        if prefered_charset:
            accept_charset = prefered_charset + accept_charset
        .... (continues)....

Of course, code should be robust to allow 'prefered_language' be
"pt-br" or ["pt-br", "pt"]...

That was my idea...

But we still have some problems/decisions to do (regarding my solution):

a) CalendarDatePicker would need to have its own
"prefered_language/prefered-charset" fields, so it could use them when
instantiating the internal LocalizableJSLink...
Now image if a third party calendar didn't care about been localizable
friendly..

b) To solve (a), maybe it could be interesting to have a setup once
mechanism... like doing this:

    LocalizableJSLink.prefered_language = "pt-br"

So, any widget that make use of LocalizableJSLink, like calendar core
widgets or that UltraMegaYearThirdPartyCalendar would be automatically
configured... but that leads to another problem: TG 1.1 aims to allow
multiple TG applications running in the same process... and as far I
understand, this "setup" would affect all the applications....



I should note that there is a ML thread that talks about it [1]:

Your solution is about having another widget... mine was about using
the old LocalizableJSLink... but both try to solve I problem that is
real....  :)

My 2c....

Cheers

Roger


[1] 
http://groups.google.com/group/turbogears/browse_thread/thread/cf51b0cd475e9ec6/900961d8a23bedcf#900961d8a23bedcf




On 6/3/06, Max Ischenko <[EMAIL PROTECTED]> wrote:
>
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to