GithubHelp home page GithubHelp logo

stephan765 / spring-icu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meticoeus/spring-icu

0.0 1.0 0.0 118 KB

Provides the ICU4J's message formatting features, such as named arguments support, flexible plural formatting, rule based number format, date interval formats

License: Apache License 2.0

Java 100.00%

spring-icu's Introduction

ICU Support Grails Plugin

Provides the ICU4J message formatting features, such as named arguments support, flexible plural formatting, rule based number format, date interval formats.

Features

Named arguments

By default Spring allows you to use only numbered arguments in i18n messages. ICU4j support named arguments using Map, which are sometimes are more readable. For example:

numbered={0}, you have {1} unread messages of {2}
names={username}, you have {unread} unread messages of {total}

With ICU4J, you can do this:

String message = icuMessageSource.getMessage("names", [username: 'John', unread: 12, total: 200], locale)

will output John, you have 12 unread messages of 200.

Plural formatting

Pluralisation in English is pretty simple and can be implemented using embedded ChoiceFormat. However, many other languages have more complex pluralisation rules described here, which cannot be handled by default. The plugin provides a simple pluralization using a language's rules, e.g. for Polish:

plural={0} {0, plural, one{auto}few{auta}many{aut}other{aut}}
String message = icuMessageSource.getMessage("plural", [7], locale)

will output 3 auta, 7 aut.

Rule based number formatting

amount={0, spellout} dollars
String message = icuMessageSource.getMessage("amount", [12045], locale)

will output twelve thousand forty-five dollars.

Other features

  • ICU implements a more user-friendly apostrophe quoting syntax. In message text, an apostrophe only begins quoting literal text if it immediately precedes a syntax character (mostly {curly braces}). By default an apostrophe always begins quoting, which requires common text like "don't" and "aujourd'hui" to be written with doubled apostrophes like "don''t" and "aujourd''hui".
  • Many more date formats: month+day, year+month,...
  • Date interval formats: "Dec 15-17, 2009"

Spring Boot Usage

Define the bean. messageSource currently causes errors. See issues

@Bean
public ICUMessageSource icuMessageSource() {
    ICUReloadableResourceBundleMessageSource messageSource = new ICUReloadableResourceBundleMessageSource();
    messageSource.setBasename("classpath:locale/messages");
    messageSource.setCacheSeconds(3600);
    return messageSource;
}

Place your message properties files

src/main/resources/locale

License

This library is available under the Apache License, Version 2.0.

(c) All rights reserved

spring-icu's People

Contributors

burtbeckwith avatar meticoeus avatar mochalov avatar nancyd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.