1 package be
.nikiroo
.fanfix
.bundles
;
4 import java
.io
.IOException
;
5 import java
.util
.Locale
;
7 import be
.nikiroo
.utils
.resources
.TransBundle
;
10 * This class manages the translation resources of the application.
14 public class StringIdBundle
extends TransBundle
<StringId
> {
18 * Create a translation service for the given language (will fall back to
19 * the default one i not found).
24 public StringIdBundle(String lang
) {
25 super(StringId
.class, Target
.resources
, lang
);
30 * Return the currently used language as a String.
32 * @return the language
34 * @deprecated use the call from {@link TransBundle} when available
36 public Locale
getLanguage() {
37 return getLocaleFor(lang
);
41 * Update resource file.
47 * in case of I/O error
49 public static void main(String
[] args
) throws IOException
{
50 String path
= new File(".").getAbsolutePath()
51 + "/src/be/nikiroo/fanfix/bundles/";
52 new StringIdBundle(null).updateFile(path
);
53 System
.out
.println("Path updated: " + path
);
57 * Return the {@link Locale} representing the given language.
60 * the language to initialise, in the form "en-GB" or "fr" for
63 * @return the corresponding {@link Locale} or the default {@link Locale} if
66 * @deprecated Use the call from {@link TransBundle} when available.
68 static private Locale
getLocaleFor(String language
) {
71 if (language
== null) {
72 locale
= Locale
.getDefault();
74 language
= language
.replaceAll("_", "-");
75 String lang
= language
;
76 String country
= null;
77 if (language
.contains("-")) {
78 lang
= language
.split("-")[0];
79 country
= language
.split("-")[1];
83 locale
= new Locale(lang
, country
);
85 locale
= new Locale(lang
);