-
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
Draft
phorward
wants to merge
7
commits into
viur-framework:main
Choose a base branch
from
phorward:fix-translations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dd62d69
fix: General fixing and clean-up on `translate()`
phorward adf1330
feat: Replace former `get_public()` by universal `dump()`
phorward 9ce7c94
fix linter issues
phorward 13c3efc
fixed comment
phorward 16426e8
Improved add_missing_translations
phorward 68a421b
Merge branch 'main' into fix-translations
sveneberth 048ae0e
feat: Implement default_variables; Resolves #1379
sveneberth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,7 +205,12 @@ def __str__(self) -> str: | |
|
||
from viur.core.render.html.env.viur import translate as jinja_translate | ||
|
||
if self.key not in systemTranslations and conf.i18n.add_missing_translations: | ||
if ( | ||
not self.key.startswith("core.") | ||
and not self.key.startswith("viur.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wip |
||
and self.key not in systemTranslations | ||
and conf.i18n.add_missing_translations | ||
): | ||
# This translation seems to be new and should be added | ||
filename = lineno = None | ||
is_jinja = False | ||
|
@@ -428,6 +433,10 @@ def add_missing_translation( | |
public: bool = False, | ||
) -> None: | ||
"""Add missing translations to datastore""" | ||
|
||
logging.error(f"{key=} {hint=} {default_text=} {filename=} {lineno=} {variables=} {public=}") | ||
raise RuntimeError("ICH WILL DAS NICHT") | ||
|
||
try: | ||
from viur.core.modules.translation import TranslationSkel, Creator | ||
except ImportError as exc: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. important! |
||
descr=translate( | ||
"core.translationskel.tr_key.descr", | ||
"viur.core.translationskel.tr_key.descr", | ||
"Translation key", | ||
), | ||
searchable=True, | ||
unique=UniqueValue(UniqueLockMethod.SameValue, False, | ||
"This translation key exist already"), | ||
unique=UniqueValue( | ||
UniqueLockMethod.SameValue, | ||
False, | ||
"This translation key exist already" | ||
), | ||
) | ||
|
||
translations = StringBone( | ||
descr=translate( | ||
"core.translationskel.translations.descr", | ||
"viur.core.translationskel.translations.descr", | ||
"Translations", | ||
), | ||
searchable=True, | ||
languages=conf.i18n.available_dialects, | ||
params={ | ||
"tooltip": translate( | ||
"core.translationskel.translations.tooltip", | ||
"viur.core.translationskel.translations.tooltip", | ||
"The languages {{main}} are required,\n {{accent}} can be filled out" | ||
)(main=", ".join(conf.i18n.available_languages), | ||
accent=", ".join(conf.i18n.language_alias_map.keys())), | ||
|
@@ -48,7 +52,7 @@ class TranslationSkel(Skeleton): | |
|
||
translations_missing = SelectBone( | ||
descr=translate( | ||
"core.translationskel.translations_missing.descr", | ||
"viur.core.translationskel.translations_missing.descr", | ||
"Translation missing for language", | ||
), | ||
multiple=True, | ||
|
@@ -64,37 +68,37 @@ class TranslationSkel(Skeleton): | |
|
||
default_text = StringBone( | ||
descr=translate( | ||
"core.translationskel.default_text.descr", | ||
"viur.core.translationskel.default_text.descr", | ||
"Fallback value", | ||
), | ||
) | ||
|
||
hint = StringBone( | ||
descr=translate( | ||
"core.translationskel.hint.descr", | ||
"viur.core.translationskel.hint.descr", | ||
"Hint / Context (internal only)", | ||
), | ||
) | ||
|
||
usage_filename = StringBone( | ||
descr=translate( | ||
"core.translationskel.usage_filename.descr", | ||
"viur.core.translationskel.usage_filename.descr", | ||
"Used and added from this file", | ||
), | ||
readOnly=True, | ||
) | ||
|
||
usage_lineno = NumericBone( | ||
descr=translate( | ||
"core.translationskel.usage_lineno.descr", | ||
"viur.core.translationskel.usage_lineno.descr", | ||
"Used and added from this lineno", | ||
), | ||
readOnly=True, | ||
) | ||
|
||
usage_variables = StringBone( | ||
descr=translate( | ||
"core.translationskel.usage_variables.descr", | ||
"viur.core.translationskel.usage_variables.descr", | ||
"Receives these substitution variables", | ||
), | ||
readOnly=True, | ||
|
@@ -103,7 +107,7 @@ class TranslationSkel(Skeleton): | |
|
||
creator = SelectBone( | ||
descr=translate( | ||
"core.translationskel.creator.descr", | ||
"viur.core.translationskel.creator.descr", | ||
"Creator", | ||
), | ||
readOnly=True, | ||
|
@@ -113,24 +117,24 @@ class TranslationSkel(Skeleton): | |
|
||
public = BooleanBone( | ||
descr=translate( | ||
"core.translationskel.public.descr", | ||
"viur.core.translationskel.public.descr", | ||
"Is this translation public?", | ||
), | ||
defaultValue=False, | ||
) | ||
|
||
@classmethod | ||
def write(cls, skelValues: SkeletonInstance, **kwargs) -> db.Key: | ||
def write(cls, skel: SkeletonInstance, **kwargs) -> db.Key: | ||
# Ensure we have only lowercase keys | ||
skelValues["tr_key"] = skelValues["tr_key"].lower() | ||
return super().write(skelValues, **kwargs) | ||
skel["tr_key"] = skel["tr_key"].lower() | ||
return super().write(skel, **kwargs) | ||
|
||
@classmethod | ||
def preProcessSerializedData(cls, skelValues: SkeletonInstance, entity: db.Entity) -> db.Entity: | ||
def preProcessSerializedData(cls, skel: SkeletonInstance, entity: db.Entity) -> db.Entity: | ||
# Backward-compatibility: re-add the key for viur-core < v3.6 | ||
# TODO: Remove in ViUR4 | ||
entity["key"] = skelValues["tr_key"] | ||
return super().preProcessSerializedData(skelValues, entity) | ||
entity["key"] = skel["tr_key"] | ||
return super().preProcessSerializedData(skel, entity) | ||
|
||
|
||
class Translation(List): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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