Skip to content
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

Merged
merged 8 commits into from Jul 5, 2021
Merged

Conversation

mattias-p
Copy link
Member

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 and get_test_results RPC-API methods and we don't have any automatic tests for those.

@mattias-p mattias-p added this to the v2021.2 milestone Jun 18, 2021
@mattias-p mattias-p changed the title Validate locale Refactor locale validation Jun 18, 2021
@mattias-p mattias-p requested review from matsduf and a user June 18, 2021 15:21
@mattias-p mattias-p marked this pull request as ready for review June 18, 2021 15:22
@ghost ghost mentioned this pull request Jun 29, 2021
ghost
ghost previously approved these changes Jun 29, 2021
Copy link

@ghost ghost left a 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)

ghost
ghost previously approved these changes Jul 1, 2021
Copy link

@ghost ghost left a 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.

@@ -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.";
Copy link

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -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.";
Copy link
Contributor

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.

Copy link
Member Author

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.

@mattias-p mattias-p merged commit 3de3333 into zonemaster:develop Jul 5, 2021
@mattias-p
Copy link
Member Author

I've tested this v2021.2 and it LGTM.

I've run:

  • zmb get_language_tags a couple of times with different LANGUAGE.locale settings
  • zmtest both with and without the --lang option
    Both seems to work fine.

@mattias-p mattias-p added the S-ReleaseTested Status: The PR has been successfully tested in release testing label Nov 19, 2021
@mattias-p mattias-p deleted the validate-locale branch July 19, 2023 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-ReleaseTested Status: The PR has been successfully tested in release testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants