i18n.properties 未找到 OpenUI5

i18n.properties Not Found OpenUI5

我在VS2013开发OpenUi5项目时遇到国际化问题。无法获取 i18n.properties:

"GET http://localhost:28091/i18n/i18n.properties 404 (Not Found) sap-ui-core.js:126 "

这是我的项目设置:

./i18n/i18n.属性

 showHello=Hello

./internationization/Main.controller.js

 onInit: function() {
    var oResourceModel = new sap.ui.model.resource.ResourceModel({
        bundleName : "i18n.i18n"
    });

    sap.ui.getCore().setModel(oResourceModel, "i18n");
},

./internationization/Main.view.xml

 <core:View 
        xmlns:core="sap.ui.core" 
        xmlns:mvc="sap.ui.core.mvc" 
        xmlns="sap.m"
       controllerName="internationization.Main"
       xmlns:html="http://www.w3.org/1999/xhtml">

       <Page title="Title">
           <content>
              <Button text="{i18n>showHello}"/>
           </content>
       </Page>
 </core:View>

非常感谢您的提前帮助。

实例化时需要指定绝对路径ResorceModel

路径将从项目名称开始,因此如果 myProject 是您项目的名称,则代码将为:

var oResourceModel = new sap.ui.model.resource.ResourceModel({
    bundleName : "myProject.i18n.i18n"
});

我在使用 Visual Studios 开发网络服务器时遇到了同样的问题。

您必须通过在项目根目录的 web.config 中提供 mime 映射来配置它以部署 .properties 文件:

<configuration>
  <system.webServer>
    <staticContent>
      <mimeMap fileExtension=".properties" mimeType="application/text"/>
    </staticContent>
  </system.webServer>
</configuration>

如果缺少,只需添加 <mimeMap/> 元素及其父元素。