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
Refactor locale validation #799
Conversation
4067f81
to
1e4ed14
Compare
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.
Looks good to me (and Travis has already been run on the last commit, and is happy)
7d41974
to
b6485f9
Compare
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.
looks good, beside 2 small typos.
lib/Zonemaster/Backend/Config.pm
Outdated
@@ -184,6 +185,11 @@ sub parse { | |||
$obj->_set_SQLITE_database_file( $value ) | |||
if $obj->DB_engine eq 'SQLite'; | |||
} | |||
if ( defined( my $value = $ini->val( 'LANGUAGE', 'locale' ) ) ) { | |||
if ( $value eq "" ) { | |||
push @warnings, "Use of empty LANGUAGE.locale propery is deprecated. Remove LANGUAGE.locale entry or specify LANUGAGE.locale = en_US instead."; |
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.
typos:
- propery -> property
- LANUGAGE -> LANGUAGE
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.
Fixed
lib/Zonemaster/Backend/Config.pm
Outdated
@@ -184,6 +185,11 @@ sub parse { | |||
$obj->_set_SQLITE_database_file( $value ) | |||
if $obj->DB_engine eq 'SQLite'; | |||
} | |||
if ( defined( my $value = $ini->val( 'LANGUAGE', 'locale' ) ) ) { | |||
if ( $value eq "" ) { | |||
push @warnings, "Use of empty LANGUAGE.locale propery is deprecated. Remove LANGUAGE.locale entry or specify LANUGAGE.locale = en_US instead."; |
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.
The documentation says: "Leaving the locale key empty or absent is deprecated. Always configure it with supported locale tags." Having no LANGUAGE.locale is deprecated.
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 removed the deprecation of absent LANGAUGE.locale. That way we don't have to force users who don't care about native language support to add this property to their configuration files when we finally remove the feature. Having a default value of "en_US" is perfectly reasonable.
I've tested this v2021.2 and it LGTM. I've run:
|
Purpose
This PR refactors the implementation of LANGUAGE.locale.
Context
This PR extends the use of patterns for API and validation introduced in #759 and #757 to also cover the LANGUAGE.locale property.
These changes were developed in parallel with #759 and #757 as part of resolving #685. These changes are not part for solving in a technical sense, because the validations were already there. But they are in an architectural sense because they make the Config module interface more cohesive. These changes also played an important role when designing the new Config module interface, its internal structure and the new validation framework.
Changes
The methods Language_Locale_hash() and ListLanguageTags() are replaced by the LANGUAGE_locale() getter.
Call sites are updated to use the new getter instead.
The internal representation of the LANGUAGE.locale property within the Config is updated to reflect a little more of its structure as described in the configuration documentation.
The assignment of the default value for LANGUAGE.locale is placed together with the other properties.
How to test this PR
This PR is a pure refactoring so it should not affect any functionality, and it does add a few new tests at the unit level. That said it modifies code used by the
get_language_tags
andget_test_results
RPC-API methods and we don't have any automatic tests for those.