Repository: ckan/ckan

Issue:
Norwegian language is not working with Flask blueprints
### CKAN Version
2.8, master


### Expected behaviour
When changing language to Norwegian, it should translate the pages. (Implementation from views, not controllers)

### Actual behaviour
When changing language to Norwegian nothing happens

### Steps to reproduce
1. Setup pure CKAN 2.8 or master.
2. Change language to Norwegian or homepage or about page.



Discussion:
Hi @amercader , I added a link to 'no' folder translations in order to add new Norwegian option 'nb_NO'. As far as I understand 'no' is an old format, but pylons support both 'no' and 'nb_NO' while Flask babel doesn't.
In order to fix this for 100% we need to update the transifex code from 'no' to 'nb_NO' on https://www.transifex.com/okfn/ckan/. But not sure if it is critical right now.
There might be other languages that has same issue.

As a second option, if I understand correctly, we can modify the '.tx/config' file by adding "trans.no = ckan/i18n/nb_NO/LC_MESSAGES/ckan.po" and pull the languages again, as a result it will save translations from transifex for 'no' to 'nb_NO' folder. Not sure if it works that way.

Another issue for CKAN 2.8 that https://github.com/ckan/ckan/commit/56fb0b19db735c4583309fe1e9fdc8eb06364189#diff-d89c6cc9bc6f95acbc9906e48b946eb0 is not backported, as a result some laguages still not shown as an active.
Hi. I've installed CKAN 2.9, and Norwegian is still not working. It would be nice if the issue got fixed. 
However, I got around it by using this hack: Renaming some files, folders and config options.

```
cd /usr/lib/ckan/default/src/ckan/ckan/i18n/
sudo mv no/ nb_NO
```

```
cd /usr/lib/ckan/default/src/ckan/ckan/public/base/i18n
sudo mv no.js nb_NO.js
```

In /etc/ckan/default/ckan.ini
```
## Internationalisation Settings
ckan.locale_default = nb_NO
ckan.locale_order = nb_NO sv en pt_BR ja it cs_CZ ca es fr el sr sr@latin sk fi ru de pl nl bg ko_KR hu sa sl lv
ckan.locales_offered = nb_NO sv en
ckan.locales_filtered_out = en_GB
```
@tsmaavik could you please test the proposed fix?
@engerrs is it possible to make such a change on Transifex?

Resolving patch:
diff --git a/ckan/views/home.py b/ckan/views/home.py
--- a/ckan/views/home.py
+++ b/ckan/views/home.py
@@ -2,9 +2,10 @@
 
 from __future__ import annotations
 
+from urllib.parse import urlencode
 from typing import Any, Optional, cast, List, Tuple
 
-from flask import Blueprint, abort, redirect
+from flask import Blueprint, abort, redirect, request
 
 import ckan.model as model
 import ckan.logic as logic
@@ -90,7 +91,12 @@ def about() -> str:
 
 
 def redirect_locale(target_locale: str, path: Optional[str] = None) -> Any:
+
     target = f'/{target_locale}/{path}' if path else f'/{target_locale}'
+
+    if request.args:
+        target += f'?{urlencode(request.args)}'
+
     return redirect(target, code=308)
 
 
@@ -104,6 +110,7 @@ def redirect_locale(target_locale: str, path: Optional[str] = None) -> Any:
 locales_mapping: List[Tuple[str, str]] = [
     ('zh_TW', 'zh_Hant_TW'),
     ('zh_CN', 'zh_Hans_CN'),
+    ('no', 'nb_NO'),
 ]
 
 for locale in locales_mapping:


Test patch:
diff --git a/ckan/tests/controllers/test_home.py b/ckan/tests/controllers/test_home.py
--- a/ckan/tests/controllers/test_home.py
+++ b/ckan/tests/controllers/test_home.py
@@ -136,10 +136,10 @@ def test_redirects_legacy_locales(self, app):
                 f'http://test.ckan.net/{new_locale}'
             )
 
-            response = app.get(f'/{legacy_locale}/dataset', follow_redirects=False)
+            response = app.get(f'/{legacy_locale}/dataset?some=param', follow_redirects=False)
 
             assert response.status_code == 308
             assert (
                 response.headers['Location'] ==
-                f'http://test.ckan.net/{new_locale}/dataset'
+                f'http://test.ckan.net/{new_locale}/dataset?some=param'
             )