2017-10-08 52 views
0

阿羅哈傢伙,如何翻譯膠子桌面PROGRAMM

  1. 你能解釋一下什麼這可以很好的文件? 在項目瀏覽器中 - > Gradle:org.controlsfx:controlsfx:8.40.12 - > Resource Bundel'controlsfx' - >這裏是不同語言的不同文件。我可以用這個翻譯我的程序內容英語,德國,波蘭語,我可以編輯它

    2.如果第一個是一個愚蠢的IDEE我怎麼能翻譯它? 我愛迪是做翻譯的屬性湖這個english.properties,germany.properties,polish.properties資源 保存loade本

    stateManager.setPersistenceMode(StateManager.PersistenceMode.USER); 
    

    嘗試{ 輸入=新的FileInputStream(stateManager.getProperty( 「Languge」 ).orElse(「」)。toString()。trim()+「。properties」); //加載屬性文件 prop.load(input);

    // get the property value and print it out 
        System.out.println(prop.getProperty("database")); 
        System.out.println(prop.getProperty("dbuser")); 
        System.out.println(prop.getProperty("dbpassword")); 
    
    } catch (IOException ex) { 
        ex.printStackTrace(); 
    } finally { 
        if (input != null) { 
         try { 
          input.close(); 
         } catch (IOException e) { 
          e.printStackTrace(); 
         } 
        } 
    } 
    

回答

0

如果創建與膠子插件您的IDE桌面項目,例如使用多視圖項目模板,你會發現,每個視圖有一個屬性文件。

此默認屬性文件包含英文鍵值。但是,您可以輕鬆創建該文件的副本,使用不同的區域設置對其進行重命名,並使用相同的鍵提供該區域設置的值。

例如,對於primary.properties

label.text=Welcome 
button.text=Go to Secondary View 

,你可以在同一個包創建primary_es.properties,具有:

label.text=Bienvenido 
button.text=Ir a Vista Secundaria 

一旦你有幾個區域設置爲給定的屬性文件,你的IDE將顯示所有一次:

netbeans locale

就是這樣,你不需要改變代碼中的任何東西。默認語言環境將用於選擇正確的屬性文件。

顯然,您可以在運行時選擇不同的區域設置。對於您將不得不使用不同的資源包:

@Override 
public void init() { 
    // other Locale different than the default: 
    resourceBundle = ResourceBundle.getBundle(
      "<your.views.package>.primary", 
      Locale.ENGLISH); 
    ... 
} 
0

@何佩雷達

你我的samthing這樣的屬性? image where i save Properties

我也這在我的WelcomeController

public void initialize() { 
    String language; 
    Locale currentLocale; 
    language = new String("pl"); 
    currentLocale = new Locale(language); 
    ResourceBundle resourceBundle = ResourceBundle.getBundle("bundles/language",currentLocale); 

    System.out.println(resourceBundle.getString("greetings")); 
} 

我這樣做

language = new String("pl"); 

因爲這

Locale.ENGLISH 

不要有一個靜態Locale.POLISH

我也將是(德國或取消|波蘭或PL |英語或中文)保存例如不會在用戶C的設置

與此 stateManager.setPersistenceMode(StateManager.PersistenceMode.USER); stateManager.setProperty("language", "de" );

或更好PROGRAMM設置:\用戶\ Harry05.gluon-particle

+0

請不要將您的評論添加爲答案。只需編輯您的問題併發布到那裏。然後刪除這個答案。至於你的問題,是的,我的意思是像'language_XX.properties'文件。 –