如何在多个磁贴(项目)中加载共享的i18n文件?

时间:2018-06-01 01:28:48

标签: sapui5

我们的fiori应用程序中有大约十个磁贴,我将共享文件放在/ common中,下图显示了项目结构(/ analytics,/ appsettings ...除了/ common之外的所有磁贴):

enter image description here

许多i18n在瓷砖之间是相同的,所以我想保持所有i18n in / common。

在/analytic/webapp/Component.js中,我定义了i18n资源:

init: function() {
  UIComponent.prototype.init.apply(this, arguments);

  // resourceroots is also defined in manifest.json,
  // why I defined resourceroots thrice is another topic, it's stupid, I know
  jQuery.sap.registerModulePath("myprojectcommon", "./../../common");
  jQuery.sap.registerModulePath("myproject.common", "/myproject/resources/common/");

  myprojectcommon.util.Utils.setComponent(this);

  var setComponentCommonResource = myprojectcommon.util.Utils.setCommonResource.bind(this);

  setComponentCommonResource();
}

/普通/ UTIL / utils的:

setCommonResource: function() {
  var i18nModel = new sap.ui.model.resource.ResourceModel({
    bundleName: "myproject.common.i18n.i18n"
  });

  this.setModel(i18nModel, "i18n");
}

现在加载了常见的i18n,但是在manifest.json中定义的i18n失败了,例如

"sap.app": {
  "title": "{{appTitle}}",
  "description": "{{appDescription}}"
}

结果如何:

enter image description here

我该怎么办?

似乎没有API在Component.js中设置titlehttps://sapui5.hana.ondemand.com/#/api/sap.ui.core.UIComponent

相关问题:One app with multiple component.js: How to load shared modules?

1 个答案:

答案 0 :(得分:1)

修复
"sap.app": {
  "i18n": "./../../common/i18n/i18n.properties"
}

"sap.ui5": {
  "resourceRoots": {
    "myprojectcommon": "./../../common/"
  },
  "models": {
    "i18n": {
      "type": "sap.ui.model.resource.ResourceModel",
      "settings": {
        "bundleName": "myprojectcommon.i18n.i18n"
      }
  },
}

下面是ui5如何加载i18n文件的位置: https://github.com/SAP/openui5/blob/c014e24356497a44125c1dd5419fdf536119600e/src/sap.ui.core/src/sap/ui/core/Manifest.js#L200