Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

L10nMessages is a library that makes internationalization (i18n) and localization (l10n) of Java applications easy and safe.

License

NotificationsYou must be signed in to change notification settings

pinterest/l10nmessages

BuildLicenseMaven CentraljavadocInstallation

L10nMessages is a library that makes internationalization (i18n) and localization (l10n) of Javaapplications easy and safe.

It provides afluent API to load andformat messages that is built on top of Java standard libraries. In addition to simplifying theoverall setup, it brings strong typing and compile time checks to the mix when used with theannotation processor.

Full Documentation

The full documentation ishere.

Installation

Seegeneral instructions andguides forBazel,Gradle andMaven.

Getting Started

Also available in thefull documentation (with filepaths).

Create a resource bundle

Create a root file:Messages.properties in thecom.pinterest.l10nmessages.example package.

The corresponding resource bundlebaseName iscom.pinterest.l10nmessages.example.Messages.

UTF-8 is the recommended encoding for theproperties files.

In a project that follows the Maven layout, the file would be:

welcome_user=Welcome {username}!

Register the resource bundle with@L10nProperties

Add the@L10nProperties annotation to the application class to register the resource bundle withthe annotation processor.

importcom.pinterest.l10nmessages.L10nProperties;@L10nProperties(baseName ="com.pinterest.l10nmessages.example.Messages")publicclassApplication {}

Enum generated by the annotation processor

Compile your project. The annotation processor should generate the followingenum:

packagecom.pinterest.l10nmessages.example;publicenumMessages {welcome_user("welcome_user");publicstaticfinalStringBASENAME ="com.pinterest.l10nmessages.example.Messages";// ...}

Strong typing using Enum

Thatenum can be used to create theL10nMessages instance and then to format a message using thetyped key:Messages.welcome_user. The argument:username is provided as a key/value pair.

importcom.pinterest.l10nmessages.L10nMessages;importcom.pinterest.l10nmessages.L10nProperties;@L10nProperties(baseName ="com.pinterest.l10nmessages.example.Messages")publicclassApplication {publicstaticvoidmain(String[]args) {L10nMessages<Messages>m =L10nMessages.builder(Messages.class).build();StringlocalizedMsg =m.format(Messages.welcome_user,"username","Mary");System.out.println(localizedMsg);// Welcome Mary!  }}

For extra typing, considerargument names typing.

Localization

Localize the root properties file by creating the fileMessages_fr.properties for "French"

welcome_user=Bienvenue {username}!

Specify the locale wanted for the messages

@L10nProperties(baseName ="com.pinterest.l10nmessages.example.Messages")publicclassApplication {publicstaticvoidmain(String[]args) {L10nMessages<Messages>m =L10nMessages.builder(Messages.class)        .locale(Locale.FRENCH)        .build();StringlocalizedMsg =m.format(Messages.welcome_user,"username","Mary");System.out.prinln(localizedMsg);// Bienvenue Mary!  }}

About

L10nMessages is a library that makes internationalization (i18n) and localization (l10n) of Java applications easy and safe.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp