diff --git a/README.md b/README.md index b684b07..cf3469f 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,12 @@ io.github.alaugks spring-messagesource-base - 0.1.0.1-SNAPSHOT + 1.0.0.rc1-SNAPSHOT ``` -## Configuration +## MessageSource Configuration ```java import io.github.alaugks.spring.messagesource.base.catalog.Catalog; import io.github.alaugks.spring.messagesource.base.catalog.CatalogHandler; @@ -36,13 +36,31 @@ public class MessageConfig { public MessageSource messageSource() { List translations = new ArrayList<>(); - translations.add(new Translation(Locale.forLanguageTag("en"), "hello_world", "Hello World")); - translations.add(new Translation(Locale.forLanguageTag("de"), "hello_world", "Hallo Welt")); + + var localeEn = Locale.forLanguageTag("en"); + translations.add(new Translation(localeEn, "headline", "Headline")); + translations.add(new Translation(localeEn, "postcode", "Postcode")); + translations.add(new Translation(localeEn, "email-notice", "Your email {0} has been registered.")); + translations.add(new Translation(localeEn, "default-message", "This is a default message.")); + translations.add(new Translation(localeEn, "headline", "Payment", "payment")); + translations.add(new Translation(localeEn, "expiry_date", "Expiry date", "payment")); + + var localeEnUs = Locale.forLanguageTag("en-US"); + translations.add(new Translation(localeEnUs, "postcode", "Zip code")); + translations.add(new Translation(localeEnUs, "expiry_date", "Expiration date", "payment")); + + var localeDe = Locale.forLanguageTag("de"); + translations.add(new Translation(localeDe, "headline", "Überschrift")); + translations.add(new Translation(localeDe, "postcode", "Postleitzahl")); + translations.add(new Translation(localeDe, "email-notice", "Ihre E-Mail {0} wurde registriert.")); + translations.add(new Translation(localeDe, "default-message", "Das ist ein Standardtext.")); + translations.add(new Translation(localeDe, "headline", "Zahlung", "payment")); + translations.add(new Translation(localeDe, "expiry_date", "Ablaufdatum", "payment")); return new BaseTranslationMessageSource( CatalogHandler .builder( - new Catalog( + new Catalog( translations, Locale.forLanguageTag("en") ) @@ -53,6 +71,167 @@ public class MessageConfig { } ``` + +### Target values + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
idenen-USdejp***
headline*
messages.headline
HeadlineHeadline**ÜberschriftHeadline
postcode*
messages.postcode
PostcodeZip codePostleitzahlPostcode
email-notice*
messages.email-notice
Your email {0} has been registered.Your email {0} has been registered.**Ihre E-Mail {0} wurde registriert.Your email {0} has been registered.
default-message*
messages.default-message
This is a default message.This is a default message.**Das ist ein Standardtext.This is a default message.
payment.headlinePaymentPayment**ZahlungPayment
payment.expiry_dateExpiry dateExpiration dateAblaufdatumExpiry date
+ +> *Default domain is `messages`. +> +> **Example of a fallback from Language_Region (`en-US`) to Language (`en`). The `id` does not exist in `en-US`, so it tries to select the translation with locale `en`. +> +> ***There is no translation for Japanese (`jp`). The default locale translations (`en`) are selected. + + + +## Using the MessageSource + +With the implementation and use of the MessageSource interface, the translations are also available in **Thymeleaf**, as **Service (Dependency Injection)** and **Custom Validation Messages**. Also in packages and implementations that use the MessageSource. + +### Thymeleaf + +With the configured MessageSource, the translations are available in Thymeleaf. + +```html + + + +

+

+ + +