当前位置: 首页 > article >正文

SAP UI5 walkthrough step8 Translatable Texts

在这个章节,我们会将一些文本常量独立出一个资源文件

这样的话,可以方便这些文本常量被翻译成任意的语言

这种国际化的操作,我们一般命名为i18n

新建一个文件i18n.properties

webapp/i18n/i18n.properties (New)

showHelloButtonText=Say Hello
helloMsg=Hello {0}

接着我们将这些常量,绑定到Controller.js

controller/App.controller.js

sap.ui.define([
   "sap/ui/core/mvc/Controller",
   "sap/m/MessageToast",
   "sap/ui/model/json/JSONModel",
   "sap/ui/model/resource/ResourceModel"
], (Controller, MessageToast, JSONModel, ResourceModel) => {
   "use strict";

   return Controller.extend("ui5.walkthrough.controller.App", {
     onInit() {
         // set data model on view
         const oData = {
            recipient : {
               name : "World"
            }
         };
         const oModel = new JSONModel(oData);
         this.getView().setModel(oModel);

         // set i18n model on view
         const i18nModel = new ResourceModel({
            bundleName: "ui5.walkthrough.i18n.i18n"
         });
         this.getView().setModel(i18nModel, "i18n");
      },

      onShowHello() {
         // read msg from i18n model
         const oBundle = this.getView().getModel("i18n").getResourceBundle();
         const sRecipient = this.getView().getModel().getProperty("/recipient/name");
         const sMsg = oBundle.getText("helloMsg", [sRecipient]);

         // show message
         MessageToast.show(sMsg);
      }
   });
});

另外将view.xml中的常量文本替代

webapp/view/App.view.xml

<mvc:View
   controllerName="ui5.walkthrough.controller.App"
   xmlns="sap.m"
   xmlns:mvc="sap.ui.core.mvc">
   <Button
      text="{i18n>showHelloButtonText}"
      press=".onShowHello"/>
   <Input
      value="{/recipient/name}"
      description="Hello {/recipient/name}"
      valueLiveUpdate="true"
      width="60%"/>
</mvc:View>

Conventions

  • The resource model for internationalization is called the i18n model.

  • The default filename is i18n.properties.

  • Resource bundle keys are written in (lower) camelCase.

  • Resource bundle values can contain parameters like {0}{1}{2}, …

  • Never concatenate strings that are translated, always use placeholders.

  • Use Unicode escape sequences for special characters.


http://www.kler.cn/news/163345.html

相关文章:

  • 【密码学引论】密码协议
  • nginx反向代理到aws S3 ,解决S3返回500、502、503错误
  • 微信小程序 纯css画仪表盘
  • CCKS2023-面向金融领域的主体事件检测-亚军方案分享
  • javascript实现Stack(栈)数据结构
  • PySpark开发环境搭建常见问题及解决
  • 网站内容审核功能的重要性
  • MYSQL练题笔记-子查询-换座位
  • unity 2d 入门 飞翔小鸟 小鸟碰撞 及死亡(九)
  • EOCR-CT电流互感器与SR-CT区别简介
  • 『Linux升级路』进度条小程序
  • vue使用甘特图dhtmlxgantt + gantt.addTaskLayer
  • 基于高通MSM8953平台android9.0的GPIO驱动开发
  • Hbase JAVA API 增删改查操作
  • 【电子取证篇】汽车取证数据提取与汽车取证实例浅析(附标准下载)
  • imazing正在查找最新的apple mobile device组件
  • SpringBoot AOP切面实现对自定义注解的属性动态修改
  • 无重复字符的最长子串(LeetCode 3)
  • 记录一下Mac配置SpringBoot开发环境
  • “华为杯”研究生数学建模竞赛2016年-【华为杯】A题:无人机在抢险救灾中的优化运用(附获奖论文及MATLAB代码实现)
  • perf与火焰图-性能分析工具
  • IntelliJ IDEA使用Eval Reset
  • Unity使用打成图集的Sprite作为模型贴图使用的问题
  • ubuntu server 20.04 备份和恢复 系统 LTS
  • 小红书用户采集工具:掌握策略,轻松吸引潜在客户
  • 【flink番外篇】1、flink的23种常用算子介绍及详细示例(1)- map、flatmap和filter
  • 【链表Linked List】力扣-82 删除链表中的重复元素II
  • velocity-engine-core是什么?Velocity模板引擎的使用
  • pr抖音素材42个手机竖屏抖音视频转场特效PR剪辑模板
  • 浅谈5G基站节能及数字化管理解决方案的设计与应用-安科瑞 蒋静