-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: General fixing and clean-up on translate()
#1364
base: main
Are you sure you want to change the base?
Conversation
This pull request summarizes several problems: 1. Let all ViUR-core related translations have a `viur.core`-tr_key-prefix 2. Make `tr_key` required 3. Provide a way for `conf.i18n.add_missing_translations` to only add or ingore a specific pattern (fnmatch)
src/viur/core/i18n.py
Outdated
not self.key.startswith("core.") | ||
and not self.key.startswith("viur.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wip
src/viur/core/bones/select.py
Outdated
if self.languages: | ||
prefix = self.translation_key_prefix | ||
if callable(prefix): | ||
prefix = prefix(self) | ||
|
||
values = { | ||
key: label if isinstance(label, translate) else translate( | ||
f"{prefix}{label}", str(label), | ||
f"value {key} for {self.name}<{type(self).__name__}> in {self.skel_cls.__name__} in {self.skel_cls}" | ||
) | ||
for key, label in values.items() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wip
@@ -21,25 +21,29 @@ class TranslationSkel(Skeleton): | |||
kindName = KINDNAME | |||
|
|||
tr_key = StringBone( | |||
required=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
important!
- SelectBone now allowes for a separate `add_missing_translations`-parameter - `conf.i18n.add_missing_translations` can now be also an iterable of fnmatch-patterns - `translate`-class allowes for individual `add_missing`-flag
Conflicts: src/viur/core/i18n.py
) | ||
if self.key not in systemTranslations: | ||
# either the translate()-object has add_missing set | ||
if not (add_missing := self.add_missing): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this behaviour confusing.
- So I set
add_missing
set toFalse
, but ifconf.i18n.add_missing_translations
isTrue
, it is added anyway.
Ifadd_missing
is set toTrue
, it doesn't matter what is inconf.i18n.add_missing_translations
and it's added too.
I would see this as a common condition:
If self.add_missing
and conf.i18n.add_missing_translations
are both True
, add, otherwise not.
This pull request summarizes several problems:
viur.core
-tr_key-prefixtr_key
requiredconf.i18n.add_missing_translations
to only add or ingore a specific pattern (fnmatch)translation.dump()
function for JSON-based retrieval of both public and private translations.SelectBone
with auto-create-translation-flagdefault_variables
Implementdefault_variables
ini18n.translate
#1379translate
-Module a standard view for System-translations + Public translationstranslate
to use it askey
for the new object