MessageBundle.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00010 package com.generalrobotix.ui.util;
00011 
00012 import java.util.Locale;
00013 import java.util.ResourceBundle;
00014 import com.generalrobotix.ui.util.GrxDebugUtil;
00015 
00016 public class MessageBundle {
00017     private static MessageBundle this_;
00018     protected static ResourceBundle messages_;
00019 
00020     private MessageBundle() {
00021         messages_ =
00022             ResourceBundle.getBundle("com.generalrobotix.messages", Locale.US);
00023     }
00024 
00025     private  MessageBundle(Locale locale) {
00026         messages_ = ResourceBundle.getBundle("com.generalrobotix.messages", locale);
00027     }
00028 
00029     public static final void setLocale(Locale locale) {
00030         if (this_ == null) {
00031             this_ = new MessageBundle(locale);
00032         } else {
00033             messages_ =
00034                 ResourceBundle.getBundle("com.generalrobotix.messages", locale);
00035         }
00036     }
00037 
00038     public static final void setLocale(String language, String country) {
00039         if (this_ == null) {
00040             this_ = new MessageBundle(new Locale(language, country));
00041         } else {
00042             messages_ =
00043                 ResourceBundle.getBundle(
00044                     "com.generalrobotix.messages",
00045                     new Locale(language, country)
00046                 );
00047         }
00048     }
00049 
00050     public static final String get(String key) {
00051         if (this_ == null) {
00052             this_ = new MessageBundle(Locale.getDefault());
00053         }
00054         try{
00055                 return messages_.getString(key);
00056         }catch(Exception e){
00057                 try{
00058                         GrxDebugUtil.println("not found " + key + "in messages_(defaultlocale).properties");
00059                         return ResourceBundle.getBundle("com.generalrobotix.messages", Locale.US).getString(key);
00060                 }catch(Exception e1){
00061                         GrxDebugUtil.println("not found " + key + "in messages_en.properties");
00062                         return "";
00063                 }
00064         }
00065     }
00066     
00067     public static final ResourceBundle getMessages() { return messages_; }
00068 } 


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:17