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

Fix locale #1557

Closed
wants to merge 3 commits into from
Closed

Fix locale #1557

wants to merge 3 commits into from

Conversation

ildyria
Copy link
Member

@ildyria ildyria commented Oct 16, 2022

Add tests to remove overflowing-unused translations.

@ildyria ildyria added this to the 4.6.2 milestone Oct 16, 2022
@codecov
Copy link

codecov bot commented Oct 16, 2022

Codecov Report

Merging #1557 (e0f9e5c) into master (f4702d7) will decrease coverage by 0.74%.
The diff coverage is n/a.

Additional details and impacted files

@nagmat84
Copy link
Collaborator

Could we wait with this PR until after #1494 has been merged? I guess a lot of it will be solved by then and merging this PR now only makes it harder to get #1494 out of the door. #1494 is only waiting for LycheeOrg/Lychee-front#322 to be merged.

@ildyria
Copy link
Member Author

ildyria commented Oct 16, 2022

@nagmat84 this PR just makes a minor changes to some of the local and add tests to ensure consistency. I fail to see how this impacts much #1494 which is in draft mode. :)
Furthermore, this is more like a PR in advance of your future comments on #1539 where you are going to for an external PR on some sections. :D

}

/**
* Test Languages are strictly.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment doesn't seem to explain anything?


foreach ($keys as $key) {
try {
static::assertArrayHasKey($key, $full, 'Language ' . $lang_test->code() . ' as too many keys.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
static::assertArrayHasKey($key, $full, 'Language ' . $lang_test->code() . ' as too many keys.');
static::assertArrayHasKey($key, $full, 'Language ' . $lang_test->code() . ' has too many keys.');

Would it make sense to also print the extra key? Or is that done already?

@nagmat84
Copy link
Collaborator

#1494 which is in draft mode. :)

This PR is only in draft mode as a safety measure such you do not accidentally merge it.

It already has been approved by you and @kamil4 and I am not doing anything on it but keeping it up-to-date with current changes. The obstacle is that #1494 uses unicode char points which our current frontend can not properly handle in all places. Hence, #1519 needs to be merged first, but then there is nothing else which prevents #1494 from being merged, too.

Copy link
Collaborator

@nagmat84 nagmat84 left a comment

Choose a reason for hiding this comment

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

I am in strict favor to not change the current locale files. I just jumped into the middle of them and first six keys which have been removed are actually used currently. I stopped checking at this point. A simple grep did the job.

Moreover, this clean-up is already made in #1494 which has already been approved.

However, I am fine with improving the test for language consistency.

@@ -303,7 +302,6 @@ public function get_locale(): array
'SUCCESS' => 'OK',
'RETRY' => 'Opakovať',

'SETTINGS_WARNING' => 'Zmena rozšírených nastavení môže mať negatívny vplyv na stabilitu, bezpečnosť a rýchlosť tejto aplikácie. Upravujte len to, o čom presne viete, čo robíte.',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one is actually used in view.js by view.full_settings.content.init. We must not delete it.

Comment on lines -315 to -316
'SETTINGS_SUCCESS_CSS' => 'CSS aktualizované',
'SETTINGS_SUCCESS_UPDATE' => 'Nastavenia úspešne aktualizované',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same thing here, see settings.js method settings.changeCSS. Don't delete it.

Comment on lines -388 to -389
'CSS_TEXT' => 'Vlastné CSS:',
'CSS_TITLE' => 'CSS zmeniť',
Copy link
Collaborator

Choose a reason for hiding this comment

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

And again. See view.js method view.settings.content.setCSS.

}
}

static::assertEquals('en', Lang::get_code());
static::assertEquals('OK', Lang::get('SUCCESS'));
$this->assertFalse($failed);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Error: Static method 'assertFalse' should not be called dynamically

Suggested change
$this->assertFalse($failed);
static::assertFalse($failed);

Which is also rather obvious compared with the two lines above.

Comment on lines +76 to +82
foreach ($keys as $key) {
try {
static::assertArrayHasKey($key, $full, 'Language ' . $lang_test->code() . ' as too many keys.');
} catch (ExpectationFailedException $e) {
$msgSection->writeln('<comment>Error:</comment> ' . $e->getMessage());
$failed = true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of looping across all the keys we could simply use the PHP native method array_diff_key. It should make the code a little bit more efficient (not that I care such much about it in the test), but it should also make the code much more clearer and easier to grasp.

Moreover, this test method and the test method above could be combined into one. Basically, they do the same thing just with swapped roles. So that is the pseudo code:

public function testLanguageConsistency(): void {
	$englishDictionary = Lang::get_lang();
	$availableDictionaries = Lang::get_lang_available();
	$failed = false;
	foreach ($availableDictionaries as $locale) {
		$dictionary = Lang::factory()->make($locale);
		$missingKeys = array_diff_key(englishDictionary, $dictionary);
		$extraKeys = array_diff_key($dictionary, englishDictionary);
		if (size($missingKeys) !== 0) {
			$msgSection->writeln(sprintf('<comment>Error:</comment> Locale %s misses the following keys: %s', $locale, implode($missingKeys, ', ')));
			$falied = true;
		}
		if (size($extraKeys) !== 0) {
			$msgSection->writeln(sprintf('<comment>Error:</comment> Locale %s has the following extra keys: %s', $locale, implode($extraKeys, ', ')));
			$falied = true;
		}
	}
	static::assertFalse($failed);
}

@ildyria
Copy link
Member Author

ildyria commented Oct 17, 2022

I am in strict favor to not change the current locale files. I just jumped into the middle of them and first six keys which have been removed are actually used currently. I stopped checking at this point. A simple grep did the job.

Moreover, this clean-up is already made in #1494 which has already been approved.

However, I am fine with improving the test for language consistency.

Then I will close that one and directly open a PR on #1494 But then it will have to be merged before #1539 :)

@ildyria ildyria closed this Oct 17, 2022
@nagmat84 nagmat84 deleted the fix-locale branch October 21, 2022 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants