-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
536 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
core/src/main/java/com/squarespace/template/LocaleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.squarespace.template; | ||
|
||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import com.squarespace.cldrengine.CLDR; | ||
|
||
public class LocaleManager { | ||
|
||
public static final String DEFAULT = "main"; | ||
private final Map<String, Entry> entries = new HashMap<>(2); | ||
|
||
public LocaleManager() { | ||
this.entries.put(DEFAULT, new Entry(Locale.US)); | ||
} | ||
|
||
public LocaleManager(Locale locale) { | ||
this.entries.put(DEFAULT, new Entry(locale)); | ||
} | ||
|
||
public void setLocale(Locale locale) { | ||
this.entries.put(DEFAULT, new Entry(locale)); | ||
} | ||
|
||
public void addLocale(String name, Locale locale) { | ||
this.entries.put(name, new Entry(locale)); | ||
} | ||
|
||
public Entry get() { | ||
return this.entries.get(DEFAULT); | ||
} | ||
|
||
public Entry get(String name) { | ||
Entry entry = this.entries.get(name); | ||
return entry == null ? this.entries.get(DEFAULT) : entry; | ||
} | ||
|
||
public static class Entry { | ||
|
||
private final Locale locale; | ||
private final CLDR cldr; | ||
private MessageFormats formatter; | ||
|
||
public Entry(Locale locale) { | ||
this.locale = locale; | ||
this.cldr = CLDR.get(locale); | ||
} | ||
|
||
public Locale locale() { | ||
return this.locale; | ||
} | ||
|
||
public CLDR cldr() { | ||
return this.cldr; | ||
} | ||
|
||
public MessageFormats formatter() { | ||
if (this.formatter == null) { | ||
this.formatter = new MessageFormats(this.cldr); | ||
} | ||
return this.formatter; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.