-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
[Feature] Improve legal code language selection/fallback #483
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -89,11 +89,11 @@ def get_translation_object( | |
|
||
# Add a fallback to the standard Django translation for this language. This | ||
# gets us the non-legal-code parts of the pages. | ||
if language_code in settings.LANGUAGES_MOSTLY_TRANSLATED: | ||
if language_code in settings.LANGUAGES_AVAILABLE_DEEDS_UX: | ||
tool_translation_object.add_fallback( | ||
translation.trans_real.translation(language_code) | ||
) | ||
elif language_default in settings.LANGUAGES_MOSTLY_TRANSLATED: | ||
elif language_default in settings.LANGUAGES_AVAILABLE_DEEDS_UX: | ||
tool_translation_object.add_fallback( | ||
translation.trans_real.translation(language_default) | ||
) | ||
|
@@ -253,20 +253,30 @@ def map_legacy_to_django_language_code(legacy_language_code: str) -> str: | |
return django_language_code | ||
|
||
|
||
def get_default_language_for_jurisdiction_deed(jurisdiction_code): | ||
def get_default_language_for_jurisdiction_deed_ux(jurisdiction_code): | ||
default_language = DEFAULT_JURISDICTION_LANGUAGES.get( | ||
jurisdiction_code, settings.LANGUAGE_CODE | ||
) | ||
if default_language in settings.LANGUAGES_MOSTLY_TRANSLATED: | ||
if default_language in settings.LANGUAGES_AVAILABLE_DEEDS_UX: | ||
return default_language | ||
else: | ||
return settings.LANGUAGE_CODE | ||
|
||
|
||
def get_default_language_for_jurisdiction_naive(jurisdiction_code): | ||
return DEFAULT_JURISDICTION_LANGUAGES.get( | ||
jurisdiction_code, settings.LANGUAGE_CODE | ||
) | ||
def get_default_language_for_jurisdiction_legal_code(jurisdiction_code): | ||
default_language = DEFAULT_JURISDICTION_LANGUAGES.get(jurisdiction_code, settings.LANGUAGE_CODE) | ||
if default_language in settings.LANGUAGES_AVAILABLE_LEGAL_CODE: | ||
return default_language | ||
else: | ||
return settings.LANGUAGE_CODE | ||
|
||
|
||
def load_legal_code_translations(jurisdiction_code): | ||
settings.LANGUAGES_AVAILABLE_LEGAL_CODE = { | ||
# Populate this dictionary with the available translations for legal code | ||
"en": "English", | ||
"fr": "French", | ||
} | ||
|
||
|
||
def get_jurisdiction_name(category, unit, version, jurisdiction_code): | ||
|
@@ -310,7 +320,8 @@ def load_deeds_ux_translations(): | |
that meet or exceed the TRANSLATION_THRESHOLD). | ||
""" | ||
deeds_ux_po_file_info = {} | ||
languages_mostly_translated = [] | ||
# languages_mostly_translated = [] | ||
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. better to remove instead of comment out |
||
languages_available_deeds_ux = [] | ||
for language_code, pofile_path in get_deeds_ux_pofiles(): | ||
pofile_obj = polib.pofile(pofile_path) | ||
percent_translated = pofile_obj.percent_translated() | ||
|
@@ -326,12 +337,12 @@ def load_deeds_ux_translations(): | |
and language_code != settings.LANGUAGE_CODE | ||
): | ||
continue | ||
languages_mostly_translated.append(language_code) | ||
languages_available_deeds_ux.append(language_code) | ||
deeds_ux_po_file_info = dict(sorted(deeds_ux_po_file_info.items())) | ||
# Add global settings | ||
settings.DEEDS_UX_PO_FILE_INFO = deeds_ux_po_file_info | ||
settings.LANGUAGES_MOSTLY_TRANSLATED = sorted( | ||
list(set(languages_mostly_translated)) | ||
settings.LANGUAGES_AVAILABLE_DEEDS_UX = sorted( | ||
list(set(languages_available_deeds_ux)) | ||
) | ||
|
||
|
||
|
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
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.
function rename is incomplete: