【问题标题】:about how translate gluon Desktop Programm关于如何翻译 gluon 桌面程序
【发布时间】:2017-10-08 16:05:27
【问题描述】:

阿罗哈,

  1. 你能解释一下这个文件有什么好处吗? 在项目资源管理器中 -> Gradle: org.controlsfx:controlsfx:8.40.12 -> Resource Bundel 'controlsfx' -> 这里是不同语言的不同文件。我可以用这个翻译我的 Programm 内容英语、德国、波兰语吗?我可以让它可编辑吗

    2.如果第一个是一个愚蠢的想法,我该如何翻译? 我的想法是让翻译属性湖这个english.properties,Germany.properties,polish.properties 节省资源 用这个加载

        stateManager.setPersistenceMode(StateManager.PersistenceMode.USER);
    

    试试{ input = new FileInputStream( stateManager.getProperty("Languge").orElse("").toString().trim()+".properties");// 加载一个属性文件 prop.load(输入);

        // 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();
            }
        }
    }
    

【问题讨论】:

    标签: javafx gluon gluon-desktop


    【解决方案1】:

    如果您使用 Gluon 插件为您的 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 将同时显示所有内容:

    就是这样,您无需更改代码中的任何内容。默认语言环境将用于选择正确的属性文件。

    显然,您可以在运行时选择不同的语言环境。为此,您将不得不使用不同的资源包:

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

    【讨论】:

      【解决方案2】:

      @何塞·佩雷达

      您是否会像这样为属性挖掘类似的东西? 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

      i 也将被保存为例如(Germany or de|Polish or pl|English or en)作为设置

      有了这个 stateManager.setPersistenceMode( StateManager.PersistenceMode.USER); stateManager.setProperty( "language", "de" );

      或更好的程序设置不在用户 C:\Users\Harry05.gluon-particle 中

      【讨论】:

      • 请不要添加您的 cmets 作为答案。只需编辑您的问题并将其发布在那里。然后删除此答案。至于你的问题,是的,我的意思是language_XX.properties 文件。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-04
      • 2016-09-18
      • 1970-01-01
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多