diff --git a/docs/changelog.rst b/docs/changelog.rst index c7f0eebb10..bbed433a54 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -5,6 +5,11 @@ CHANGELOG 2.101.2+dev (XXXX-XX-XX) ------------------------ +**Bug fixes** + +- Fix sub-language usage (en-US, zh-hant, ...) (#3801) + + 2.101.2 (2023-10-17) ------------------------ diff --git a/geotrek/common/management/commands/update_post_migration_languages.py b/geotrek/common/management/commands/update_post_migration_languages.py index 1a87c4c93d..5d42753430 100644 --- a/geotrek/common/management/commands/update_post_migration_languages.py +++ b/geotrek/common/management/commands/update_post_migration_languages.py @@ -17,25 +17,27 @@ class Command(BaseCommand): def execute(self, *args, **options): self.stdout.write("Update objects translation after migration from .po files") for lang in settings.MODELTRANSLATION_LANGUAGES: + correct_lang = lang.replace('-', '_') self.stdout.write("Lang : {lang}".format(lang=lang)) with translation.override(lang, deactivate=True): self.stdout.write("TargetPortal") # 'Geotrek Rando' => TargetPortal title TargetPortal.objects.filter( - **{'title_{}'.format(lang): ''} - ).update(**{'title_{}'.format(lang): _('Geotrek Rando')}) + **{'title_{}'.format(correct_lang): ''} + ).update(**{'title_{}'.format(correct_lang): _('Geotrek Rando')}) # 'Geotrek is a web app ...' => TargetPortal description TargetPortal.objects.filter( - **{'description_{}'.format(lang): ''} - ).update(**{'description_{}'.format(lang): _('Geotrek is a web app allowing you to prepare your ' - 'next trekking trip !')}) + **{'description_{}'.format(correct_lang): ''} + ).update( + **{'description_{}'.format(correct_lang): _('Geotrek is a web app allowing you to prepare your ' + 'next trekking trip !')}) self.stdout.write("Label is park centered") Label.objects.filter(pk=1).filter( - Q(**{'name_{}'.format(lang): ''}) | Q(**{'name_{}'.format(lang): None}) - ).update(**{'name_{}'.format(lang): _('Is in the midst of the park')}) + Q(**{'name_{}'.format(correct_lang): ''}) | Q(**{'name_{}'.format(correct_lang): None}) + ).update(**{'name_{}'.format(correct_lang): _('Is in the midst of the park')}) Label.objects.filter(pk=1).filter( - Q(**{'advice_{}'.format(lang): ''}) | Q(**{'advice_{}'.format(lang): None}) - ).update(**{'advice_{}'.format(lang): _('The national park is an unrestricted natural area but ' - 'subjected to regulations which must be known ' - 'by all visitors.')}) + Q(**{'advice_{}'.format(correct_lang): ''}) | Q(**{'advice_{}'.format(correct_lang): None}) + ).update(**{'advice_{}'.format(correct_lang): _('The national park is an unrestricted natural area but ' + 'subjected to regulations which must be known ' + 'by all visitors.')}) self.stdout.write("Done.") diff --git a/geotrek/common/utils/postgresql.py b/geotrek/common/utils/postgresql.py index c70c3be9c5..dbe997fc49 100644 --- a/geotrek/common/utils/postgresql.py +++ b/geotrek/common/utils/postgresql.py @@ -47,6 +47,12 @@ def load_sql_files(app, stage): logger.info("Loading initial SQL data from '%s'" % sql_file) template = get_template(sql_file) context_settings = settings.__dict__['_wrapped'].__dict__ + # fix languages in sql TEMPLATES + # (django-modeltranslations use _ instead of - in sub languages) + fixed_languages = [] + for language in context_settings['MODELTRANSLATION_LANGUAGES']: + fixed_languages.append(language.replace('-', '_')) + context_settings['MODELTRANSLATION_LANGUAGES'] = fixed_languages context = dict( schema_geotrek=schema, schema_django=schema_django, diff --git a/geotrek/infrastructure/migrations/0028_infrastructure_published_translation.py b/geotrek/infrastructure/migrations/0028_infrastructure_published_translation.py index 21fbfd30f0..a036f07c97 100644 --- a/geotrek/infrastructure/migrations/0028_infrastructure_published_translation.py +++ b/geotrek/infrastructure/migrations/0028_infrastructure_published_translation.py @@ -12,11 +12,11 @@ def forward(apps, schema_editor): if cursor.fetchone(): for lang in settings.MODELTRANSLATION_LANGUAGES: cursor.execute( - f"SELECT 1 FROM information_schema.columns WHERE table_name='infrastructure_infrastructure' AND column_name='published_{lang}'" + f"SELECT 1 FROM information_schema.columns WHERE table_name='infrastructure_infrastructure' AND column_name='published_{lang.replace('-', '_')}'" ) if not cursor.fetchone(): cursor.execute( - f"ALTER TABLE infrastructure_infrastructure ADD published_{lang} Boolean DEFAULT True;" + f"ALTER TABLE infrastructure_infrastructure ADD published_{lang.replace('-', '_')} Boolean DEFAULT True;" ) diff --git a/geotrek/infrastructure/migrations/0029_auto_20220314_0912.py b/geotrek/infrastructure/migrations/0029_auto_20220314_0912.py index 05ff422aa4..e2227345cf 100644 --- a/geotrek/infrastructure/migrations/0029_auto_20220314_0912.py +++ b/geotrek/infrastructure/migrations/0029_auto_20220314_0912.py @@ -8,7 +8,7 @@ def forward(apps, schema_editor): with schema_editor.connection.cursor() as cursor: for lang in settings.MODELTRANSLATION_LANGUAGES: cursor.execute( - f"UPDATE infrastructure_infrastructure SET published_{lang} = False WHERE published = False; " + f"UPDATE infrastructure_infrastructure SET published_{lang.replace('-', '_')} = False WHERE published = False; " ) diff --git a/geotrek/infrastructure/migrations/0030_auto_20220314_1429.py b/geotrek/infrastructure/migrations/0030_auto_20220314_1429.py index 82c6c7b52c..2031c6cb1e 100644 --- a/geotrek/infrastructure/migrations/0030_auto_20220314_1429.py +++ b/geotrek/infrastructure/migrations/0030_auto_20220314_1429.py @@ -8,7 +8,7 @@ def forward(apps, schema_editor): with schema_editor.connection.cursor() as cursor: for lang in settings.MODELTRANSLATION_LANGUAGES: cursor.execute( - f"ALTER TABLE infrastructure_infrastructure ALTER COLUMN published_{lang} SET DEFAULT FALSE;" + f"ALTER TABLE infrastructure_infrastructure ALTER COLUMN published_{lang.replace('-', '_')} SET DEFAULT FALSE;" ) diff --git a/geotrek/signage/migrations/0022_auto_20220314_1048.py b/geotrek/signage/migrations/0022_auto_20220314_1048.py index 96e1277ff7..6bd698bcec 100644 --- a/geotrek/signage/migrations/0022_auto_20220314_1048.py +++ b/geotrek/signage/migrations/0022_auto_20220314_1048.py @@ -12,11 +12,11 @@ def forward(apps, schema_editor): if cursor.fetchone(): for lang in settings.MODELTRANSLATION_LANGUAGES: cursor.execute( - f"SELECT 1 FROM information_schema.columns WHERE table_name='signage_signage' AND column_name='published_{lang}'" + f"SELECT 1 FROM information_schema.columns WHERE table_name='signage_signage' AND column_name='published_{lang.replace('-', '_')}'" ) if not cursor.fetchone(): cursor.execute( - f"ALTER TABLE signage_signage ADD published_{lang} Boolean DEFAULT FALSE;" + f"ALTER TABLE signage_signage ADD published_{lang.replace('-', '_')} Boolean DEFAULT FALSE;" ) diff --git a/geotrek/signage/migrations/0023_auto_20220314_1441.py b/geotrek/signage/migrations/0023_auto_20220314_1441.py index eb33e1bd2b..0587ed20f3 100644 --- a/geotrek/signage/migrations/0023_auto_20220314_1441.py +++ b/geotrek/signage/migrations/0023_auto_20220314_1441.py @@ -8,7 +8,7 @@ def forward(apps, schema_editor): with schema_editor.connection.cursor() as cursor: for lang in settings.MODELTRANSLATION_LANGUAGES: cursor.execute( - f"UPDATE signage_signage SET published_{lang} = True WHERE published = True; " + f"UPDATE signage_signage SET published_{lang.replace('-', '_')} = True WHERE published = True; " )