-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[I18n] Fixes and improves plural handling (#77)
* We compute plural rules only once. * Added a bunch of known plural rules Reducing the probability of the JS engine usage. If we never load this, it's better. All POEdit-generated rules were added. * Updated CHANGELOG * try-with-ressources to load locales * Reorder langs in comments and add script variants * Updated copyright
- Loading branch information
1 parent
fb75c6b
commit 126db0c
Showing
4 changed files
with
225 additions
and
60 deletions.
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
9 changes: 8 additions & 1 deletion
9
...ain/java/fr/zcraft/quartzlib/components/i18n/translators/gettext/GettextPOTranslator.java
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
/* | ||
* Copyright or © or Copr. QuartzLib contributors (2015 - 2020) | ||
* This file is part of QuartzLib. | ||
* | ||
* Copyright or © or Copr. ProkopyL <[email protected]> (2015 - 2021) | ||
* Copyright or © or Copr. Amaury Carrade <[email protected]> (2015 – 2021) | ||
* Copyright or © or Copr. Vlammar <[email protected]> (2019 – 2021) | ||
* | ||
* This software is a computer program whose purpose is to create Minecraft mods | ||
* with the Bukkit API easily. | ||
* | ||
* This software is governed by the CeCILL-B license under French law and | ||
* abiding by the rules of distribution of free software. You can use, | ||
|
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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
/* | ||
* Copyright or © or Copr. QuartzLib contributors (2015 - 2020) | ||
* This file is part of QuartzLib. | ||
* | ||
* Copyright or © or Copr. ProkopyL <[email protected]> (2015 - 2021) | ||
* Copyright or © or Copr. Amaury Carrade <[email protected]> (2015 – 2021) | ||
* Copyright or © or Copr. Vlammar <[email protected]> (2019 – 2021) | ||
* | ||
* This software is a computer program whose purpose is to create Minecraft mods | ||
* with the Bukkit API easily. | ||
* | ||
* This software is governed by the CeCILL-B license under French law and | ||
* abiding by the rules of distribution of free software. You can use, | ||
|
@@ -118,7 +125,7 @@ public void parse() throws CannotParsePOException { | |
return; | ||
} | ||
|
||
try { | ||
try (final BufferedReader reader = rawReader) { | ||
String line; | ||
Integer lineNumber = 0; | ||
|
||
|
@@ -129,7 +136,7 @@ public void parse() throws CannotParsePOException { | |
Map<String, String> tokens = new HashMap<>(); | ||
String lastToken = null; | ||
|
||
while ((line = rawReader.readLine()) != null) { | ||
while ((line = reader.readLine()) != null) { | ||
lineNumber++; | ||
|
||
// We don't care about trailing whitespaces | ||
|
@@ -174,17 +181,14 @@ public void parse() throws CannotParsePOException { | |
if (!tokens.isEmpty()) { | ||
analyseEntry(tokens); | ||
} | ||
|
||
// At the end we compute plural rules | ||
pluralForms = new PluralForms(pluralCount, pluralFormScript); | ||
} catch (IOException e) { | ||
throw new CannotParsePOException("An IO exception occurred while parsing the file", e); | ||
} finally { | ||
try { | ||
if (rawReader != null) { | ||
rawReader.close(); | ||
rawReader = null; | ||
} | ||
} catch (IOException ignored) { | ||
} | ||
} | ||
|
||
rawReader = null; | ||
} | ||
|
||
/** | ||
|
@@ -314,8 +318,6 @@ private void analyseEntry(Map<String, String> tokens) { | |
} | ||
} | ||
} | ||
|
||
pluralForms = new PluralForms(pluralCount, pluralFormScript); | ||
} | ||
|
||
/** | ||
|
@@ -374,7 +376,8 @@ public String getPluralFormScript() { | |
* If you can use them, it's always better. | ||
* | ||
* <p>This method can only work correctly with Plural-Forms listed at: | ||
* http://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html#Plural-forms | ||
* http://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html#Plural-forms, | ||
* as well as POEdit-generated plural forms. | ||
* | ||
* @param count The count to compute plural for. | ||
* @return The plural index. | ||
|
Oops, something went wrong.