New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simplify locales #818
simplify locales #818
Conversation
locale_n = cls.locales[lang] | ||
cls.__shared_state['current_lang'] = lang | ||
locale.setlocale(locale.LC_ALL, locale_n) | ||
return '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
would be a better idea.
(None
is also the default return value btw)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is used in templates, ralsina commented in some mail it needs to be
a string
On Fri, Oct 11, 2013 at 12:28 PM, Chris “Kwpolska” Warrick <
notifications@github.com> wrote:
In nikola/utils.py:
self.__dict__ = self.__shared_state
- @classmethod
- def set_locale(cls, lang):
"""Sets the locale for language lang, returns ''
in linux the locale encoding is set to utf8,
in windows that cannot be guaranted.
In either case, the locale encoding is available in cls.encodings[lang]
"""
# intentional non try-except: templates must ask locales with a lang,
# let the code explode here and not hide the point of failure
if lang != cls.__shared_state['current_lang']:
locale_n = cls.locales[lang]
cls.__shared_state['current_lang'] = lang
locale.setlocale(locale.LC_ALL, locale_n)
return ''
None would be a better idea.
—
Reply to this email directly or view it on GitHubhttps://github.com//pull/818/files#r6918164
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is called from templates, if it returns None you end up with 'None' in the middle of the page :-/
|
out for lunch, will look when back On Fri, Oct 11, 2013 at 12:46 PM, Chris “Kwpolska” Warrick <
|
Silly me, I forgot to load locales in Travis. Updated, lets see how it comes. |
I’d like to point you at https://travis-ci.org/getnikola/nikola/jobs/12428498#L1085 — is this correct? |
kw: yes, it is expected output when test_locale stress the sanitization subsystem with a purposely invalid locale |
Lets hear Travis opinion. Also: I situated the provision of samples to initialize LocaleBorg in testing in the same LocaleBorg; that could be moved to tests\base or somewhere if desired. |
Green and fresh as a lettuce ! I will hear request for changes, but be patient, I need to do work related duties and probably cannot retake until tomorrow (Saturday) evening. |
If you are going to use classmethods in localeBorg, then it can be just a regular class, and the init can take place outside of it, in the Nikola class, using the class just as a namespace. |
About classmethods and other things LocaleBorg Now that all the pieces are in place a rethinking of the classification in class / instance methods is in order. I think
are strong candidates for class methods: The first two are also strong candidates to live in LocaleBorg, because they need to know the internal details of LocaleBorg. The third (initialize_for_testing) simply uses the other two, so not strong case to live in LocaleBorg.
The other methods, the ones providing services, I think they want to be instance methods.
Theres not a strong case to ensure initialization in this way, we surely are trading a bit of cpu an memory overhead for sparing a bit of boilerplate code. So, meh. I have a small preference to turning services in instance methods, but thats all. Concrete questions to you, people:
|
|
Author: Claudio Canepa <ccanepacc@gmail.com>
…KOLA_LOCALE_DEFAULT and NIKOLA_LOCALE_OTHER
^^ PR updated. Rebasing branch on master shows (in the prev post) as lot of new commits but the only new are the last three. |
I'll try to do a real review of it tonight. |
# In this file we express locales in the string form that | ||
# python's locales will accept in your OS, by example | ||
# "en_US.utf8" in unix-like OS, "English_United States" in Windows. | ||
# LOCALES = dict mapping languaje --> explicit locale for the languajes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
language*
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
||
_windows_locale_guesses = { | ||
# some languages may need that the appropiate Microsoft's Language Pack | ||
# be instaled; the 'str' bit will be added in the guess function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’d love to see some documentation about this “need to have language pack”. As far as I know, Windows ships all locales (as in date/time/currency/…) and installs them all by default without an easy way to uninstall them. (this differs from UI languages, see below).
UI Languages:
- Windows 2000 (Professional/Server) and Windows XP Professional had somehow-working language packs that were hard to obtain and use
- Windows Vista/7 Ultimate/Enterprise had sane language packs everyone could download from Windows Update
- Windows 8/RT has even saner language packs that are downloaded through a separate Control Panel applet and are available for everyone (not just rich people who bothered to buy Ultimate or even richer companies with Enterprise)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I phrased as 'may need'.
I don't really expect that my spanish windows xp / 7 supports out of the box anything chinese.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m going to test it on my almost-vanilla XP/7 VMs and share the results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here we have the answer:
-
Windows XP requires East Asian language support that can be easily installed in the locale control panel (Regional & Language Settings). That requires a Windows XP CD, something I do not own (using a VM from http://modern.ie/)
-
Windows 7 has built-in support. Proof:
(for those wondering, this copy of Windows is unactivated and comes from a genuine install CD I own. It is almost-vanilla with minimum additional software.)
PS. the same is happening in the Polish locales of both (XP — tried myself, 7 — a friend told me that he had Japanese locale because he needed it for something ootb on a Polish Windows; I never owned a copy of Windows 7 in Polish and never will)
out of battery, phone line died monday night so letting here. |
I like it. +1 Great work @ccanepa I know this kind of fixes are hard and a lot of work :-) |
Thanks you both for the reviews, git advice and general patience. |
This change revamps the locale handling in Nikola.
The goals
The change in a nutshell
Backward compatibility
api compatibility
For strict compatibility I should have deprecated and retained those deleted, serving people who subclassed some parts of nikola.
I guessed there are no people using directly those functions but if desired, I can undelete those.
new feature
User can specify the exact locale to use with each language in conf.py
There are three new optional settings in conf.py related to locales
LOCALES: dict of lang: locale key-value pairs. His keys must be keys of TRANSLATIONS. Some or all keys can be omitted.
LOCALE_FALLBACK : locale to use when an explicit locale is invalid (if not set, two hardcoded locales are tried, "en" and "C", the later should be available in any host)
LOCALE_DEFAULT: guides the handling of implicit locales
An explicit locale for a language can be specified in LOCALE[language].
Explicit but invalid locales are replaced with the sanitized locale_fallback
Languages with no explicit locale are set to
Misc