Skip to content

Commit

Permalink
fix sublaguage usage (#3801)
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos committed Oct 20, 2023
1 parent 56db43f commit ab1eed5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 18 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
6 changes: 6 additions & 0 deletions geotrek/common/utils/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; "
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
)


Expand Down
4 changes: 2 additions & 2 deletions geotrek/signage/migrations/0022_auto_20220314_1048.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
)


Expand Down
2 changes: 1 addition & 1 deletion geotrek/signage/migrations/0023_auto_20220314_1441.py
Original file line number Diff line number Diff line change
Expand Up @@ -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; "
)


Expand Down

0 comments on commit ab1eed5

Please sign in to comment.