-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow the configuration of EPUBCheck’s Locale
The locale used by EPUBCheck can now be configured: - with a `--locale` option on the command line - with the `setLocale(Locale locale)` method on the `EpubCheck` class - when no locale is provided, the library will fall back to the default JVM Locale (i.e. EPUBCheck’s behavior doesn’t change) This PR introduces the following changes: - Refactored `com.adobe.epubcheck.util.Messages`: - new static `getInstance(…)` methods to get the `Messages` instance for the given (optional) locale and class name (used to resolve the name of the underlying `ResourceBundle`). - the `Messages` instances are cached in a table, keyed with locale codes and resource bundle names. - Refactored the `com.adobe.epubcheck.message` package: - `MessageDictionary` is now an interface; it's functionality is split in several classes to handle default messages, loading of override files, overridden messages, dumping message files, and severities. - messages and severities are cached. - Refactored the `org.idpf.epubcheck.util.css` package, to make it locale-aware: - a `Locale` is given as an argument to the `CSSParser` constructor - the package `Messages` class is removed, replaced by the main `com.adobe.epubcheck.util.Messages` - New `LocalizedReport` interface, extending the `Report` interface with locale getter/setter methods, representing a localizable report. - the existing `Report` interface is kept unchanged, for backwards compatibility - `MasterReport` implements this new `LocalizedReport` interface - the localization code checks if the underlying report is an instance of `LocalizedReport` before setting a new locale. - New `LocaleHolder` facility to statically store the "current" locale in a thread-local variable. This is used by libraries that cannot be configured dynamically with a new locale (like Jing). - Monkey-patch Jing's `Localizer` class to load Jing's resource bundles for the locale exposed in the `LocaleHolder` utility. - Expose the current locale in the `ValidationContext` class - Update the java sources compatibility version to 1.7 - New locale-related tests Limitations: - Jing's localization relies on the locale information exposed in a static thread-local variable (in the `LocaleHolder` class). Any new implementations of the `LocalizedReport` must make sure that the locale stored in the `LocaleHolder` is updated when the locale is changed or initialized. - The validation messages defined in the schematron schemas are still not localized. Thanks to @matthew-macgregor for the original PR contribution (#650)! Closes #650 Fixes #498
- Loading branch information
1 parent
5045d78
commit 9b24995
Showing
53 changed files
with
1,975 additions
and
1,008 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
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/adobe/epubcheck/api/LocalizableReport.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.adobe.epubcheck.api; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Extends the {@link Report} interface with a method to configure the locale | ||
* used to report messages. | ||
*/ | ||
public interface LocalizableReport extends Report | ||
{ | ||
|
||
/** | ||
* Sets the locale to use in the report's messages | ||
*/ | ||
public void setLocale(Locale locale); | ||
|
||
/** | ||
* Gets the locale to use in the report's messages | ||
*/ | ||
public Locale getLocale(); | ||
} |
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
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
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
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
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
Oops, something went wrong.