1 | // Copyright (C) 2009 Google Inc. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package com.google.caja.plugin.templates; |
16 | |
17 | import java.awt.ComponentOrientation; |
18 | |
19 | import java.util.Collections; |
20 | import java.util.LinkedHashMap; |
21 | import java.util.Locale; |
22 | import java.util.Map; |
23 | |
24 | /** |
25 | * The locale context in which a template is compiled. Encapsulates the |
26 | * message strings for a locale, and details of the character set, such as |
27 | * whether it is right-to-left or left-to-right. |
28 | * |
29 | * @author mikesamuel@gmail.com |
30 | */ |
31 | public final class IhtmlL10NContext { |
32 | private final Locale locale; |
33 | private final Map<String, LocalizedHtml> messages; |
34 | |
35 | public IhtmlL10NContext(Locale locale, Map<String, LocalizedHtml> messages) { |
36 | this.locale = locale; |
37 | this.messages = new LinkedHashMap<String, LocalizedHtml>(messages); |
38 | } |
39 | |
40 | public LocalizedHtml getMessageByName(String messageName) { |
41 | return messages.get(messageName); |
42 | } |
43 | |
44 | public boolean isLeftToRight() { |
45 | return ComponentOrientation.getOrientation(locale).isLeftToRight(); |
46 | } |
47 | |
48 | public Iterable<String> getMessageNames() { |
49 | return Collections.unmodifiableCollection(messages.keySet()); |
50 | } |
51 | |
52 | public Locale getLocale() { |
53 | return locale; |
54 | } |
55 | } |