Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[IMP] *: translation methods cleaning #38859
Extract some cleaning wanted in #30759 but not related to language packs
Only activated languages should be used in "amount to text" features. If a language code of a not-used language is used, it should be ignored for consistency with the rest of the interface.
load_lang was a kind of hybrid method trying to active or creating a language if not found. This was error prone. Instead rely on two methods with clear purpose: ResLang._create_lang(lang, lang_name=None) - create a new res.lang entry using the locale of the server return the res.lang record to match the API of _activate_lang ResLang._active_lang(code) - activate the given code lang Most of the time, _active_lang is what is expected tools.trans_load_data and IrTranslation._load_module_terms no longer activate the language if not active. Loading the translations should be explicit on an activated language, it is too error prone to silently activate/create a language if not found. Remove lang_name from trans_load_data as no longer needed.
Instead of relying on the context content, pass explicit values for overwrite and create_empty_translations applu this to trans_load and trans_load_data Adapt the test that was trying to create empty translations.
Instead of previous long methods, use a class to clarify what the export actually does. The TranslationModuleReader is written to copy the API of the TranslationFileWriter. This way, exporting translations is reduced to: 1. create a reader that will fetch all module translations (either from db or from static files) 2. create a writer in a specific format (po or csv) 3. export the content from the reader to the writer Simplify the writer by deducing modules from exported translations instead of fetching it again in a oneliner (this way can benefit from yield operations) Remove the 'all_installed' possibility in modules as it was not working (creating query with 2 WHERE clause). The new methode _get_translatable_records works on a per model basis. This will allow a big performance gain as the previous code was making a .exists() for each record individually. In the future, this method could be removed as the main goal is to test the presence of the rare attribute _translate=False.
It was misleading as only forced for translations of type 'code' but for the other translations, it was retrieved from the imported file (the comment in a .po file or column in a .csv) This will allow another optimisation in the next commit, moving to a TranslationModuleReader instance
Extract some cleaning wanted in #30759 but not related to language packs - `amount_to_text` should work only on activated languages - deprecate `load_lang` and rely on `_create_lang` or `_activate_lang` - `trans_load_data` and `_load_module_terms` no longer silently activate languages - pass explicitly parameters instead of relying on context content - replace some `IrTranslation._load_module_terms(['base'], ['fr_FR'])` by `BaseModule._update_translations(['fr_FR'])` for higher level methods - create `TranslationExporter` class to clarify the `trans_export` method (and clean dead code) closes #38859 Task-id: 2088290 Pad: https://pad.odoo.com/p/r.f6f789f8711d21314bd902972153ea9d Signed-off-by: Martin Trigaux (mat) <email@example.com>