-
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)
- 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
src/viur/core/i18n.py
Outdated
) | ||
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.
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.
Hi @sveneberth, sorry for the confusion. The initial consideration about this flag was, that either the translate-object has the add_missing
-flag on first order, and when this is not True, the globally defined logic of conf.i18n.add_missing_translations
takes place, which can either be just True, but also one or many fnmatch-style pattern to match the given translation key.
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.
it seems we have different use cases for this and other expections (you want an or
logic, I an and
). Let's talk about this in a meet.
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.
As discussed yesterday, I have implemented Always and Never in 58d2e30.
Conflicts: src/viur/core/modules/translation.py
… fix-translations
@sveneberth I'm done with my requests. Can you please add changes for your requests:
This issue is urgent, waiting for approval. |
For non-static errors with variables like ```py raise errors.NotFound(f"No valid root node found for {node=}") ``` a new `TranslationSkel` for each `node`-key would be added.
@sveneberth thanks, this looks fine so far. Can you please approve the PR, I cannot self-approve. |
|
||
# Create the key from the name on initial write! | ||
if not skel["key"]: | ||
skel["key"] = db.Key(KINDNAME, skel["name"].lower()) |
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.
This would overwrite data.
If there's already a complete skeleton with the key "foo"
, and someone clicks on add and use the same key, it would overwrite the other skel without any warning etc.
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 didn't tested this, and this is kinda hakkish, but this might solve this issue:
@classmethod
def write(cls, skel, **kwargs):
def write_with_claimed_key():
skel["key"] = db.Key(KINDNAME, skel["name"].lower())
if db.Get(skel["key"]):
raise ValueError(f'An TranslationSkel with {skel["name"]=} exists already!')
return super().write(skel, **kwargs)
# Create the key from the name on initial write!
if not skel["key"]:
if db.IsInTransaction():
return write_with_claimed_key()
else:
return db.RunInTransaction(write_with_claimed_key)
return super().write(skel, **kwargs)
@@ -799,7 +799,7 @@ def start(self): | |||
return self._user_module.render.edit( | |||
self.OtpSkel(), | |||
params={ | |||
"name": i18n.translate(self.NAME), | |||
"name": i18n.translate("viur.core.modules.user." + self.NAME), |
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.
"name": i18n.translate("viur.core.modules.user." + self.NAME), | |
"name": i18n.translate(f"viur.core.modules.user.{self.NAME}"), |
and for others please use f-string too
src/viur/core/i18n.py
Outdated
) | ||
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.
it seems we have different use cases for this and other expections (you want an or
logic, I an and
). Let's talk about this in a meet.
Co-authored-by: Sven Eberth <[email protected]>
This pull request summarizes several problems:
tr_key
intoname
name
part of the db.Key for faster retrievalviur.core
-name-prefixname
(tr_key
) required on creation (otherwise, it is kept readonly)conf.i18n.add_missing_translations
to only add or ignore a specific pattern (fnmatch)translation.dump()
function for JSON-based retrieval of both public and private translations and to handle multiple patternsconf.i18n.dump_can_view
)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