You need to enable JavaScript to run this app. Android Studio strings.xml转Eclipse属性文件翻译管理方案咨询
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio strings.xml转Eclipse属性文件翻译管理方案咨询

双端Java游戏多语言适配进展

项目开发基本情况

  • 双端客户端构成
    • 移动端客户端:基于Android Studio开发,采用strings.xml文件管理所有多语言翻译内容
    • PC端客户端:基于Eclipse开发,通过配置ResourceBundles.properties文件实现多语言支持

当前待解决的需求

  • 开发团队认可Android Studio自带的翻译编辑器交互体验,希望找到可落地的适配方案,实现以下目标:
    • 将Android Studio侧的翻译内容导出为ResourceBundle格式,或是让PC端直接读取现有strings.xml文件
    • 简化维护流程,仅维护一份统一的翻译主列表即可同时满足双端的使用需求
    • 若存在支持同时导出.properties与.xml格式的免费web端工具,也可纳入可选方案范围

端侧已实现的多语言加载逻辑

Eclipse PC端加载实现

Eclipse端多语言加载相关代码截图

public static void updateLocale() {
    Locale currentLocale = new Locale(language, country);
    try{
        File file = new File("res/gamedata");
        URL[] urls = {file.toURI().toURL()};
        ClassLoader loader = new URLClassLoader(urls);
        messages = ResourceBundle.getBundle("MessagesBundle", currentLocale, loader);
        //messages = ResourceBundle.getBundle("res/gamedata/MessagesBundle", currentLocale); //旧实现方式:要求资源文件位于类路径下才能正常加载
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                theDesktop.repaint(); //TODO:切换语言时验证该重绘逻辑是否生效
            }
        });
    } catch (MissingResourceException e){
        KisnardOnline.LOGGER.error("Language files missing", e);
        // 字符串资源加载查询失败时,使用硬编码值兜底展示
        JOptionPane.showMessageDialog(theDesktop, "Language files missing. Please reload game.", "Error", JOptionPane.ERROR_MESSAGE);
    } catch (MalformedURLException e) {
        KisnardOnline.LOGGER.error("Language files missing", e);
        JOptionPane.showMessageDialog(theDesktop, "Language files missing. Please reload game.", "Error", JOptionPane.ERROR_MESSAGE);
    }
}

Android Studio移动端加载说明

  • 核心字符串获取方法签名:public final String getString(@StringRes int resId)
  • 方法作用:从应用包内置的默认字符串资源表中,根据资源ID获取对应语言环境的本地化字符串
    Android端字符串资源管理界面截图

内容的提问来源于stack exchange,提问作者KisnardOnline

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.24 01:24:03