【问题标题】:Appcelerator Titanium Internationalization not working rightAppcelerator Titanium 国际化无法正常工作
【发布时间】:2013-04-19 01:37:37
【问题描述】:

这让我抓狂:

我最近开始研究 Appcelerator Titanium。我已经使用普通项目和使用 Alloy 构建了一些小应用程序,因此我至少了解基础知识。

我无法正常工作的一件事是 i18n 文件夹/文件。

这是我所做的: - 创建一个“默认项目” - 将文件夹添加到根目录“i18n” - 将“en”和“es”文件夹添加到“i18n” - 将“strings.xml”添加到这两个新文件夹中。 - 添加:

    <?xml version="1.0" encoding="UTF-8"?>
    <resources>
       <string name="welcome_message">Welcome TEST</string>
    </resources>

到两个strings.xml,除了es字符串中我放了“ES Welcome TEST”。 - 在 Resources -> app.js 我将“I am Window 1”更改为 L('welcome_message') - 运行应用程序

普通版和合金版都只是显示一个空白屏幕。我想让我的合金应用程序工作得最好,但据我了解,本地化代码在两个应用程序中应该是一样的。在合金中,我可能只需要把它放在样式中。

任何指针都会很棒!我看过其他声称它不起作用的帖子,但所有这些帖子要么是语法错误,要么只是设置错误。我已经复制了他们的代码并且遇到了完全相同的问题,它无法正常工作,所以我感觉我错过了一个新手步骤。

-- 这是一些截图,我刚刚创建了一个全新的常规(非合金)项目,添加了上面的代码并尝试使用 L('welcome_message') 没有运气。我尝试在新 PC 上安装所有内容,以确保我的主计算机上没有搞砸任何东西。

【问题讨论】:

  • 您是否尝试过清理和构建?
  • 我试过了,也试过像上面提到的那样创建一个空白项目,添加代码,然后第一次运行它,结果相同。

标签: android iphone titanium appcelerator titanium-alloy


【解决方案1】:

答案如下:

https://wiki.appcelerator.org/display/guides/Internationalization

默认情况下,您的清单文件不会默认设置为允许本地化,除非您选择选项卡式项目。

如果你问我有点傻。

【讨论】:

  • 它不会工作,即使在通过指南之后。我创建了 i18n 文件夹和 strings.xml 并声明了 L('password') 它在模拟器上将 UI 留空以进行翻译。
【解决方案2】:

主题海报:

我的新 string.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <string name="welcome_message">Don't Help Austin</string>
    <string name="user_agent_message">user agent set to</string>
    <string name="format_test">Your name is %s</string>
    <string name="base_ui_title">Base UI</string>
    <string name="controls_win_title">Controls</string>
    <string name="phone_win_title">Phone</string>
    <string name="platform_win_title">Platform</string>
    <string name="mashups_win_title">Mashups</string>
    <string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>

我的非合金实验截图:

对于那些希望回答该主题的问题的人,以下是可能的答案。

我的 i18n 文件夹与应用程序和插件位于同一层次结构级别,因此我的文件夹不像其他合金资源那样位于应用程序文件夹中。

index.xml

<Alloy>
    <Window class="container">
        <Label id="label" onClick="doClick"></Label>
    </Window>
</Alloy>

index.tss

".container": {
    backgroundColor:"white"
},
"Label": {
    width: Ti.UI.SIZE,
    height: Ti.UI.SIZE,
    color: "#000",
    text: L("welcome_message")
} 

字符串.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <string name="welcome_message">Welcome to Kitchen Sink for Titanium</string>
    <string name="user_agent_message">user agent set to</string>
    <string name="format_test">Your name is %s</string>
    <string name="base_ui_title">Base UI</string>
    <string name="controls_win_title">Controls</string>
    <string name="phone_win_title">Phone</string>
    <string name="platform_win_title">Platform</string>
    <string name="mashups_win_title">Mashups</string>
    <string name="ordered">Hi %1$s, my name is %2$s</string>
</resources>

当我将 L("welcome_message") 放在 index.xml 中时,它不起作用。

【讨论】:

  • 我很喜欢你的幽默感 :) 但你发布的答案对我的具体问题没有帮助。您发布的内容来自那里的许多指南,我可以直接从 github 加载项目,运行它们,它们也不起作用。这就是我今晚一直在尝试的。 eclipse中是否有我需要设置的设置,或者可能在模拟器管理器中设置?
  • @Martin 你说“当我将 L("welcome_message") 放在 index.xml 中时,它不起作用。”这是问题还是答案?因为我在合金项目中也需要它的解决方案,因为它不起作用
  • 你按照原海报详细的步骤做了吗? “这是我所做的:-创建一个“默认项目”-将文件夹添加到根目录“i18n”-将“en”和“es”文件夹添加到“i18n”-将“strings.xml”添加到这两个新文件夹“
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 2014-05-01
  • 2016-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多