moinwiki / moin-1.9

MoinMoin Wiki (1.9, also: 1.5a ... 1.8), stable, for production wikis
https://moinmo.in/
Other
140 stars 51 forks source link

i18n crash fix? #73

Open ThomasWaldmann opened 3 years ago

ThomasWaldmann commented 3 years ago

from moin-devel mailing list by Paul Boddie:

Thanks for taking care of this release!

I don't have a GitHub account that I generally use for personal projects, but 
there is one very simple patch that I would like to suggest that might help 
people generally:

----

diff --git a/MoinMoin/i18n/__init__.py b/MoinMoin/i18n/__init__.py
index 17061a83..b5abdf25 100644
--- a/MoinMoin/i18n/__init__.py
+++ b/MoinMoin/i18n/__init__.py
@@ -255,7 +255,7 @@ class Translation(object):

 def getDirection(lang):
     """ Return the text direction for a language, either 'ltr' or 'rtl'. """
-    return languages[lang]['x-direction']
+    return languages and languages[lang]['x-direction'] or 'ltr'

 def getText(original, request, lang, **kw):
     """ Return a translation of some original text.

----

Previously, when upgrading Moin, there have been times when it just breaks in 
a nasty and seemingly inexplicable way, and I am pretty sure we have had to 
troubleshoot this a few times on this list or via bug reports.

In the above, where there is some cache issue, the getDirection function fails 
because the languages mapping is not set up properly (or at the time of 
invocation), and I am not even sure that the usual "moin maint cleancache" 
advice helps.

This seems to have occurred in different forms several times over the years. 
For example:

https://moinmo.in/MoinMoinBugs/1.8TypeError_in_i18n.__init__after_upgrade
https://moinmo.in/MoinMoinBugs/I18nLanguagesNotSetInSetupI18nPreauth

Interestingly, the latter of the above bug reports links to a patch that 
potentially fixes the problem but only for WSGI. (Yes, I am still using CGI 
for the few wikis I have running.)

Anyway, thanks once again for the hard work!

Paul