Skip to content

Commit

Permalink
[I18n] Fixes and improves plural handling (#77)
Browse files Browse the repository at this point in the history
* 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
AmauryCarrade authored Apr 12, 2021
1 parent fb75c6b commit 126db0c
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 60 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ We follow semantic versioning: you can tell if a version contains breaking chang

Changes marked with :warning: are **breaking changes**.

## QuartzLib 0.0.4

_Published on April 12th, 2021_

### Changed

#### Internationalization (i18n)

- Fixed a bug where plural scripts were loaded once per translation instead of once per file.
- Optimised the plural script manager by adding many known scripts. This reduces the likelihood of
having to start a JavaScript engine, improving performance by several orders of magnitude.

## QuartzLib 0.0.3

_Published on April 11th, 2021_
Expand Down
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,
Expand Down
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,
Expand Down Expand Up @@ -118,7 +125,7 @@ public void parse() throws CannotParsePOException {
return;
}

try {
try (final BufferedReader reader = rawReader) {
String line;
Integer lineNumber = 0;

Expand All @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -314,8 +318,6 @@ private void analyseEntry(Map<String, String> tokens) {
}
}
}

pluralForms = new PluralForms(pluralCount, pluralFormScript);
}

/**
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 126db0c

Please sign in to comment.