@@ -0,0 +1,2036 @@
+/*%0D%0A * Copyright (c) 2010 C%C3%A9lio Cidral Junior%0D%0A * %0D%0A *    Licensed under the Apache License, Version 2.0 (the %22License%22);%0D%0A *    you may not use this file except in compliance with the License.%0D%0A *    You may obtain a copy of the License at%0D%0A * %0D%0A *        http://www.apache.org/licenses/LICENSE-2.0%0D%0A * %0D%0A *    Unless required by applicable law or agreed to in writing, software%0D%0A *    distributed under the License is distributed on an %22AS IS%22 BASIS,%0D%0A *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0D%0A *    See the License for the specific language governing permissions and%0D%0A *    limitations under the License.%0D%0A */%0D%0A%0D%0Apackage org.tomighty.i18n;%0D%0A%0D%0Aimport java.io.IOException;%0D%0Aimport java.io.InputStream;%0D%0Aimport java.io.InputStreamReader;%0D%0Aimport java.nio.charset.Charset;%0D%0Aimport java.util.Locale;%0D%0Aimport java.util.Properties;%0D%0A%0D%0Aimport org.tomighty.ioc.Initializable;%0D%0Aimport org.tomighty.ioc.Inject;%0D%0Aimport org.tomighty.log.Log;%0D%0A%0D%0Apublic class Messages implements Initializable %7B%0D%0A%09%0D%0A%09@Inject private Log log;%0D%0A%09private Properties messages = new Properties();%0D%0A%09%0D%0A%09@Override%0D%0A%09public void initialize() %7B%0D%0A%09%09Locale locale = Locale.getDefault();%0D%0A%09%09String localeId = locale.getLanguage()+%22_%22+locale.getCountry();%0D%0A%09%09log.info(%22Loading messages for locale %22+localeId);%0D%0A%09%09String resourceName = %22/messages_%22+localeId+%22.properties%22;%0D%0A%09%09InputStream input = getClass().getResourceAsStream(resourceName);%0D%0A%09%09if(input == null) %7B%0D%0A%09%09%09log.info(%22Messages file not found: %22+resourceName);%0D%0A%09%09%7D else %7B%0D%0A%09%09%09Charset charset = Charset.forName(%22utf-8%22);%0D%0A%09%09%09InputStreamReader reader = new InputStreamReader(input, charset);%0D%0A%09%09%09try %7B%0D%0A%09%09%09%09try %7B%0D%0A%09%09%09%09%09messages.load(reader);%0D%0A%09%09%09%09%7D finally %7B%0D%0A%09%09%09%09%09reader.close();%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D catch (IOException e) %7B%0D%0A%09%09%09%09log.error(%22Error while loading resource: %22+resourceName, e);%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A%09public String get(String name) %7B%0D%0A%09%09String key = name.replace(' ', '.');%0D%0A%09%09if(messages.containsKey(key)) %7B%0D%0A%09%09%09return messages.getProperty(key);%0D%0A%09%09%7D%0D%0A%09%09return name;%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A

Create a basic message localization component