-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add normalize language function and tests #41
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces a new Changes
Assessment against linked issues
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
cc: @SaschaCowley , @seanbudd |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
_validate/manifestLoader.py (1)
55-68
: Consider adding input validation and improving documentationThe implementation looks good but could benefit from some improvements:
- Add input validation to handle edge cases
- Fix typos in docstring ("in to" → "into", "upercase" → "uppercase")
- Add examples to the docstring
Consider this enhanced implementation:
def normalizeLanguage(lang: str) -> str: """ - Normalizes a language-dialect string in to a standard form we can deal with. - Converts any dash to underline, and makes sure that language is lowercase and dialect is upercase. + Normalizes a language-dialect string into a standard form we can deal with. + Converts any dash to underscore, and makes sure that language is lowercase and dialect is uppercase. Based on NVDA`s `languageHandler` module. + :param lang: A language code. + :raises ValueError: If the language code is empty or None + :examples: + >>> normalizeLanguage("en") + 'en' + >>> normalizeLanguage("pt-BR") + 'pt_BR' :return: A normalized language code. """ + if not lang: + raise ValueError("Language code cannot be empty") lang = lang.replace("-", "_") ld = lang.split("_") + if not ld[0]: + raise ValueError("Language part cannot be empty") ld[0] = ld[0].lower() if len(ld) >= 2: ld[1] = ld[1].upper() return "_".join(ld)_tests/test_createJson.py (1)
116-129
: Consider adding more test cases for edge casesWhile the current tests cover the basic functionality well, consider adding tests for:
Edge cases:
- Empty string input
- None input
- Multiple separators (e.g., "en_US_POSIX")
- Invalid formats (e.g., "en__US")
Additional valid cases:
- Mixed case with dash (e.g., "En-us")
- Multiple dashes (e.g., "zh-Hans-CN")
Here are some additional test methods to consider:
def test_edge_cases(self): """Test handling of invalid inputs.""" with self.assertRaises(ValueError): manifestLoader.normalizeLanguage("") with self.assertRaises(ValueError): manifestLoader.normalizeLanguage("_US") with self.assertRaises(TypeError): manifestLoader.normalizeLanguage(None) def test_complex_language_codes(self): """Test handling of complex language codes.""" self.assertEqual("zh_HANS_CN", manifestLoader.normalizeLanguage("zh-Hans-CN")) self.assertEqual("en_US", manifestLoader.normalizeLanguage("En-us"))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
_tests/test_createJson.py
(2 hunks)_validate/manifestLoader.py
(1 hunks)
🔇 Additional comments (1)
_validate/manifestLoader.py (1)
50-53
: LGTM: Clean integration of language normalization
The normalization is correctly integrated into the existing workflow, maintaining the error handling while ensuring language codes are standardized before being yielded.
Issue number
Fixes nvaccess/nvda#17527
Summary of the issue
In the add-on store, sometimes translated add-ons appear as untranslated. This can be produced when an add-on has a locale folder with a non normalized language, like ES instead of es.
In the transformation to build the views Branch using addon-datastore-transform repo, a function is used to get the available languages. Available languages are stored in a set. Moreover, when a folder is created to store json files for each available language, uppercase and lowercase folders with the same name aren't created. Consequently, if a non standard language is available, but in fact add-ons aren't translated to this language, the english translation can be copied in the folder corresponding to the standard language, even overriding the available language for the standard language.
This can be observed for "es" (spanish).
Development approach
A function has been created to normalize language, and this is used in the function to get manifest localizations. Tests have been added just for this function.
Tests performed
Unit tests.
Known issues
None. This should be tested in real life.
Summary by CodeRabbit
New Features
Bug Fixes