c10n-core

A Java library, focused on making internationalisation more modular, easier to evolve and maintain, robust-to-change and IDE-friendly without excess of external tools.

License

License

GroupId

GroupId

c10n
ArtifactId

ArtifactId

c10n-core
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

jar
Description

Description

c10n-core
A Java library, focused on making internationalisation more modular, easier to evolve and maintain, robust-to-change and IDE-friendly without excess of external tools.
Project URL

Project URL

https://github.com/rodionmoiseev/c10n
Source Code Management

Source Code Management

https://github.com/rodionmoiseev/c10n

Download c10n-core

How to add to project

<!-- https://jarcasting.com/artifacts/c10n/c10n-core/ -->
<dependency>
    <groupId>c10n</groupId>
    <artifactId>c10n-core</artifactId>
    <version>1.1</version>
</dependency>
// https://jarcasting.com/artifacts/c10n/c10n-core/
implementation 'c10n:c10n-core:1.1'
// https://jarcasting.com/artifacts/c10n/c10n-core/
implementation ("c10n:c10n-core:1.1")
'c10n:c10n-core:jar:1.1'
<dependency org="c10n" name="c10n-core" rev="1.1">
  <artifact name="c10n-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='c10n', module='c10n-core', version='1.1')
)
libraryDependencies += "c10n" % "c10n-core" % "1.1"
[c10n/c10n-core "1.1"]

Dependencies

test (4)

Group / Artifact Type Version
junit : junit jar 4.11
commons-io : commons-io jar 1.3.2
com.google.collections : google-collections jar 1.0
org.hamcrest : hamcrest-library jar 1.3

Project Modules

There are no modules declared in this project.

Cosmopolitan -- C10N

Build Status

A Java library, focused on making internationalisation more modular, easier to evolve and maintain, robust-to-change and IDE-friendly without excess of external tools. See the guide for more information.

Motivation

Compare the traditional approach using resource bundles to C10N:

Using resource bundles

First, you need to create the individual bundle files with all translations:

 # Messages_en.properties
com.example.gui.window.title = Hello, {0}!
com.example.gui.window.buttons.ok = OK
com.example.gui.window.buttons.cancel = Cancel
 # Messages_ru.properties
com.example.gui.window.title = Привет, {0}!
com.example.gui.window.buttons.ok = Да
com.example.gui.window.buttons.cancel = Отмена

Then reference messages by their keys from the source code:

ResourceBundle msg =  ResourceBundle.getBundle("Messages");
//get the message
String ok = msg.getString("com.example.gui.window.buttons.ok");
//get message with parameters
String title = MessageFormat.format(
  msg.getString("com.example.gui.window.buttons.ok"), "James");

Doable, but clumsy, and needs extra maintenance for keys.

Using C10N

C10N uses a more java-esque approach: each message is declared as a method on an interface, with all translations stored in annotations.

package com.example.gui;

public interface Window{
  @En("Hello, {0}!")
  @Ru("Привет, {0}!")
  String title(String userName);
  
  @En("OK")
  @Ru("Да")
  String ok();
  
  @En("Cancel")
  @Ru("Отмена")
  String cancel();
}

To retrieve messages

Window msg = C10N.get(Window.class);
//get message
String ok = msg.ok();
//get message with parameter
String title = msg.title("James");

Not only it is much simpler, you will never make a spelling mistake in your key, or miss a message parameter.

If required, you can opt to store all or some of you translations in resource bundles. For more details see the documentation.

Documentation

Download the latest 1.3 release from the download section.

Dependencies and Compatibility

Major project dependencies are listed below:

C10N Version Java Gradle Guice (for guice-plugin users)
>= 2.0 OpenJDK 11 6.x 4.x
1.3 OracleJDK 8 2.x 4.x
1.2 OracleJDK 6 2.x 3.x
< 1.2 OracleJDK 6 1.x 3.x

Versions

Version
1.1