mozilla / wagtail-localize-smartling

Integration between wagtail-localize and Smartling's API
Mozilla Public License 2.0
1 stars 1 forks source link

Add option to disable case-changing of language codes #18

Closed stevejalim closed 1 month ago

stevejalim commented 1 month ago

This changeset adds a new setting - REFORMAT_LANGUAGE_CODES, default True, which we can use to control whether w-l-s will reformat lang codes as part of the Smartling sync.

By default w-l-s assumes the Django project will be using Django's core default of all-lowercase language codes (compared to Smartling's mixed-case approach) and forces all lang codes to the relevant style depending on the direction of travel. This change allows us to skip that step when importing strings back into Wagtail, (and the equivalent step when sending lang codes to Smartling, too, just for consistency and no surprise).

Testing

Manually tested locally. I have a stash locally with some tests for test_utils.py but neither @override_settings nor mock.patch.object seem to work for setting fake settings during a test - the former gets ignored and the latter blows up because the patched attribute can't be deleted/changed. If anyone has a tip about that, I'd welcome it

Resolves #17

stevejalim commented 1 month ago

I did struggle with @override_settings too when doing the locale mapping callback in the first place. pytest is cool, and also a steeper learning curve than I thought it be in some places

Well I need to get better at dataclasses usage, because this caught me by surprise and stopped me using with mock.patch.object(smartling_settings, REFORMAT_LANGUAGE_CODES, some_var):

dataclasses.FrozenInstanceError: cannot assign to field 'REFORMAT_LANGUAGE_CODES'