changeset 8214:460e7d2d1b38 default-i18n

i18n: make sure 'en' in Accept-Language is recognized as having 100% coverage - i18n.lang is for source language https://github.com/cdent/paste/blob/3.2.3/paste/wsgiwrappers.py#L89 describes how paste solved the problem. TG solves the same problem (with less explanation) in https://github.com/TurboGears/tg2/blob/tg2.4.2/tg/request_local.py#L36 with fallback language specified in i18n.lang . Thus, clarify the use of i18n.lang (refining f2f7a8c1281e and 8931078f70db) and set 'en' as default value on app startup. TurboGears requires an (empty) translation for the source language which is default for i18n.lang . The empty .mo for en is created as the 4 magic .mo bytes followed by lengths of 0: printf '\x95\x04\x12\xde\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' > kallithea/i18n/en/LC_MESSAGES/kallithea.mo Based on report and analysis by Wolfgang Scherer. Also discussed upstream on https://github.com/TurboGears/tg2/pull/115 .
author Mads Kiilerich <mads@kiilerich.com>
date Sun, 05 Jan 2020 01:19:05 +0100
parents dcbf070bd8ed
children 928bc1d8b279
files development.ini docs/setup.rst kallithea/config/app_cfg.py kallithea/i18n/en/LC_MESSAGES/kallithea.mo kallithea/lib/paster_commands/template.ini.mako
diffstat 5 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/development.ini	Sat Jan 18 07:42:24 2020 +0100
+++ b/development.ini	Sun Jan 05 01:19:05 2020 +0100
@@ -90,10 +90,12 @@
 static_files = true
 
 ## Internationalization (see setup documentation for details)
-## By default, the language requested by the browser is used if available.
-#i18n.enabled = false
-## Fallback language, empty for English (valid values are the names of subdirectories in kallithea/i18n):
-i18n.lang =
+## By default, the languages requested by the browser are used if available, with English as default.
+## Set i18n.enabled=false to disable automatic language choice.
+#i18n.enabled = true
+## To Force a language, set i18n.enabled=false and specify the language in i18n.lang.
+## Valid values are the names of subdirectories in kallithea/i18n with a LC_MESSAGES/kallithea.mo
+#i18n.lang = en
 
 cache_dir = %(here)s/data
 index_dir = %(here)s/data/index
--- a/docs/setup.rst	Sat Jan 18 07:42:24 2020 +0100
+++ b/docs/setup.rst	Sun Jan 05 01:19:05 2020 +0100
@@ -80,13 +80,12 @@
 language, as indicated by the browser. Thus, different users may see the
 application in different languages. If the requested language is not available
 (because the translation file for that language does not yet exist or is
-incomplete), the language specified in setting ``i18n.lang`` in the Kallithea
-configuration file is used as fallback. If no fallback language is explicitly
-specified, English is used.
+incomplete), English is used.
 
 If you want to disable automatic language detection and instead configure a
 fixed language regardless of user preference, set ``i18n.enabled = false`` and
-set ``i18n.lang`` to the desired language (or leave empty for English).
+specify another language by setting ``i18n.lang`` in the Kallithea
+configuration file.
 
 
 Using Kallithea with SSH
--- a/kallithea/config/app_cfg.py	Sat Jan 18 07:42:24 2020 +0100
+++ b/kallithea/config/app_cfg.py	Sun Jan 05 01:19:05 2020 +0100
@@ -98,6 +98,11 @@
         # Disable transaction manager -- currently Kallithea takes care of transactions itself
         self['tm.enabled'] = False
 
+        # Set the i18n source language so TG doesn't search beyond 'en' in Accept-Language.
+        # Don't force the default here if configuration force something else.
+        if not self.get('i18n.lang'):
+            self['i18n.lang'] = 'en'
+
 
 base_config = KallitheaAppConfig()
 
Binary file kallithea/i18n/en/LC_MESSAGES/kallithea.mo has changed
--- a/kallithea/lib/paster_commands/template.ini.mako	Sat Jan 18 07:42:24 2020 +0100
+++ b/kallithea/lib/paster_commands/template.ini.mako	Sun Jan 05 01:19:05 2020 +0100
@@ -185,10 +185,12 @@
 static_files = true
 
 <%text>## Internationalization (see setup documentation for details)</%text>
-<%text>## By default, the language requested by the browser is used if available.</%text>
-#i18n.enabled = false
-<%text>## Fallback language, empty for English (valid values are the names of subdirectories in kallithea/i18n):</%text>
-i18n.lang =
+<%text>## By default, the languages requested by the browser are used if available, with English as default.</%text>
+<%text>## Set i18n.enabled=false to disable automatic language choice.</%text>
+#i18n.enabled = true
+<%text>## To Force a language, set i18n.enabled=false and specify the language in i18n.lang.</%text>
+<%text>## Valid values are the names of subdirectories in kallithea/i18n with a LC_MESSAGES/kallithea.mo</%text>
+#i18n.lang = en
 
 cache_dir = %(here)s/data
 index_dir = %(here)s/data/index