kuix教程4:国际化

教程4:国际化

Requirement 需求

Please read the Tutorial 3 first. 请阅读教程3 首。

Internationalize the application 国际化应用

下载源代码 Download this tutorial step. 下载 本教程的步骤。

I18n concepts i18n的概念

Internationalization (or i18n) with Kuix is achieve by using localized resources files. 国际化(i18n的或与Kuix是使用文件实现本地化的资源)。 Kuix provides a static method that looks for a translation for a given label and return the result as a string. Kuix提供了一个静态方法,查找一个给定的标签翻译和作为一个字符串返回结果。 This method uses the device local to select the appropriate resource file and if it cannot be found, it uses the default one. 这种方法使用的设备来选择合适的本地资源文件,如果它不能被发现,它使用默认之一。

Resource files are (by default) in the /i18n directory and should comply with the following naming convention: 资源文件(默认情况下)在/ i18n的目录,并应遵守以下命名约定:

messages.en.properties messages.en.properties
where "en" stands for the language string 其中,“恩”是指语言中的字符串

Several "system" labels - like "Ok", "Cancel", etc. - have a default translation. 几个“系统”标签 - 如“好”,“取消”,等等 - 有一个默认的转换。 So if you use some message box with buttons, you will have a default english translation for them. 因此,如果你使用一些按钮的消息框,您将有一个默认的英语为他们翻译。

The label translation method: 该标签翻译方法:

The following command, will make Kuix to look for a translation for the given label in a localized resource file or by default in /i18n/messages.properties. 下面的命令,将Kuix寻找一个在一个本地化的资源文件中给出的标签,或在/ i18n/messages.properties默认的转换。 If an entry is found, it returns the translated text otherwise it is the string of the entry. 如果一个项目被发现,它返回翻译文本,否则它是该项目的字符串。

Kuix.getMessage("OK");
 

If you want to distribute your application in 2 languages - english and french for instance -, you will have to create at least 2 files : messages.fr.properties and a default english file messages.properties. 如果您要分发您的应用程序中的2种语言 - 英语和法语,例如 - 你必须创建至少2个文件:messages.fr.properties和默认英文文件messages.properties。

The translation file syntax 翻译文件的语法

The syntax of the translation file is as simple as: 由翻译文件的语法是非常简单的:

 LABEL=translation
 

Create the labels and translate them: 创建标签和翻译它们:

create file messages.properties and set the following content: 创建文件messages.properties 并设置以下内容:

 YES=Yes NO=No OK=Ok HELLOWORLD=Hello World! ABOUT=About EXIT=Exit MORE=more... CREDITS=This helloworld is powered by Kuix! EXIT_CONFIRM=Are you sur you want to quit?
 

Create the file messages.fr.properties and set the following content: 创建文件messages.fr.properties 并设置以下内容:

 YES=Oui NO=Non OK=OK HELLOWORLD=Bonjour tout le monde ! ABOUT=A propos EXIT=Quitter MORE=plus... CREDITS=Ce Helloworld a été créé avec Kuix! EXIT_CONFIRM=Etes-vous sûr de vouloir quitter?
 

The 3 first labels are used for the popup windows and should work immediately. 3首标签用于弹出窗口,并应立即开展工作。 But we will need to reference the 3 last ones. 但是,我们需要参考去年的3。

Your project structure must be now like this : 您的项目结构必须是现在这样的:

I18n folder

编辑框使用的翻译标签

你只需要打开HelloWorldFrame类,并以各自的标签的文本:

 if ("about".equals(identifier)) { // display a popup message Kuix.alert(Kuix.getMessage("CREDITS"), KuixConstants.ALERT_OK); return false; } if ("exitConfirm".equals(identifier)) { // display a popup message Kuix.alert(Kuix.getMessage("EXIT_CONFIRM"), KuixConstants.ALERT_YES | KuixConstants.ALERT_NO, "exit", null); return false; }
 

引用在XML文件翻译的文字

Since it is not possible to call the Kuix.getMessage() method from the XML file, the fallowing syntax has been integrated to the parser so that you can reference a translated label directly: 因为它是无法调用Kuix.getMessage()从XML文件的方法,在休耕语法已经集成到分析器,让您可以直接引用翻译标签:

 %LABEL%
 

For performance considerations, variables cannot be used in the attribute but only from the XML values. 出于性能的考虑,变量不能使用的属性,但只从XML值。 As a consequence, if you want to use some translated text, you can use one of the following syntax: 因此,如果你想使用一些翻译的文本,你可以使用下面的语法之一:

  • Any text alone is interpreted as a Text node: 单是任何文字解释为一个文本 节点:

     %LABEL%
     
  • Any text in a Text node, is always associated to this node: 在任何一个文本 节点的文本,这始终是相关联的节点:

     <text>%LABEL%</text>
     
  • In a more general way, to set a node's attribute to a variable value, open a _ATTRIBUTENAME node and set its value between its opening and its closing tag: 在更一般的方式,设置一个节点的属性变量的值,打开一个_ATTRIBUTENAME节点,并设置其之间的开幕式和闭幕式标记的值:

     <text><_text>%LABEL%</_text></text>
     

编辑XML使用标签

You should get something like: 你应该是这样的:

 <screen title="helloworld"> <container style="layout:inlinelayout(false,fill);align:center"> %HELLOWORLD% <picture src="logo_community.png" /> <button onAction="about" shortcuts="1">%ABOUT%</button> <button onAction="exitConfirm" shortcuts="back|delete|0">%EXIT%</button> </container> <screenFirstMenu onAction="exit">%EXIT%</screenFirstMenu> <screenSecondmenu> %MORE% <menuPopup> <menuItem onAction="about"> %ABOUT% </menuItem> <menuItem onAction="exitConfirm"> %EXIT% </menuItem> </menuPopup> </screenSecondmenu> </screen>
 

Start 启动

Start the i18n midlet

Translation parameters 翻译参数

Note that a translation label can contain one or more parameters that will be used in the translation. 请注意,翻译标签可以包含一个或多个将在翻译中使用的参数。 This feature is especially useful when you want to mix translated and untranslated texts in the same widget. 此功能是特别有用当你想混合翻译和未翻译的文本在同一部件。

  • The syntax in the translation file is given by the example below: 翻译文件中的语法,给出了下面的例子:

     VALUES=Values: {0} {1}
     
  • In the XML file: 在XML文件:

     %VALUES(female,male)%
     
The comma is the only valid parameter delimiter. 逗号是唯一有效的参数分隔符。 Avoid using it in your parameters values. 避免使用它在你的参数值。
  • And finally in Java ME: 最后在Java ME:

     String param1 = "female"; String param2 = "male"; Kuix.getMessage("VALUES", new String[] {value1, value2});
     


基于数据挖掘的音乐推荐系统设计与实现 需要一个代码说明,不需要论文 采用python语言,django框架,mysql数据库开发 编程环境:pycharm,mysql8.0 系统分为前台+后台模式开发 网站前台: 用户注册, 登录 搜索音乐,音乐欣赏(可以在线进行播放) 用户登陆时选择相关感兴趣的音乐风格 音乐收藏 音乐推荐算法:(重点) 本课题需要大量用户行为(如播放记录、收藏列表)、音乐特征(如音频特征、歌曲元数据)等数据 (1)根据用户之间相似性或关联性,给一个用户推荐与其相似或有关联的其他用户所感兴趣的音乐; (2)根据音乐之间的相似性或关联性,给一个用户推荐与其感兴趣的音乐相似或有关联的其他音乐。 基于用户的推荐和基于物品的推荐 其中基于用户的推荐是基于用户的相似度找出相似相似用户,然后向目标用户推荐其相似用户喜欢的东西(和你类似的人也喜欢**东西); 而基于物品的推荐是基于物品的相似度找出相似的物品做推荐(喜欢该音乐的人还喜欢了**音乐); 管理员 管理员信息管理 注册用户管理,审核 音乐爬虫(爬虫方式爬取网站音乐数据) 音乐信息管理(上传歌曲MP3,以便前台播放) 音乐收藏管理 用户 用户资料修改 我的音乐收藏 完整前后端源码,部署后可正常运行! 环境说明 开发语言:python后端 python版本:3.7 数据库:mysql 5.7+ 数据库工具:Navicat11+ 开发软件:pycharm
MPU6050是一款广泛应用在无人机、机器人和运动设备中的六轴姿态传感器,它集成了三轴陀螺仪和三轴加速度计。这款传感器能够实时监测并提供设备的角速度和线性加速度数据,对于理解物体的动态运动状态至关重要。在Arduino平台上,通过特定的库文件可以方便地与MPU6050进行通信,获取并解析传感器数据。 `MPU6050.cpp`和`MPU6050.h`是Arduino库的关键组成部分。`MPU6050.h`是头文件,包含了定义传感器接口和函数声明。它定义了类`MPU6050`,该类包含了初始化传感器、读取数据等方法。例如,`begin()`函数用于设置传感器的工作模式和I2C地址,`getAcceleration()`和`getGyroscope()`则分别用于获取加速度和角速度数据。 在Arduino项目中,首先需要包含`MPU6050.h`头文件,然后创建`MPU6050`对象,并调用`begin()`函数初始化传感器。之后,可以通过循环调用`getAcceleration()`和`getGyroscope()`来不断更新传感器读数。为了处理这些原始数据,通常还需要进行校准和滤波,以消除噪声和漂移。 I2C通信协议是MPU6050与Arduino交互的基础,它是一种低引脚数的串行通信协议,允许多个设备共享一对数据线。Arduino板上的Wire库提供了I2C通信的底层支持,使得用户无需深入了解通信细节,就能方便地与MPU6050交互。 MPU6050传感器的数据包括加速度(X、Y、Z轴)和角速度(同样为X、Y、Z轴)。加速度数据可以用来计算物体的静态位置和动态运动,而角速度数据则能反映物体转动的速度。结合这两个数据,可以进一步计算出物体的姿态(如角度和角速度变化)。 在嵌入式开发领域,特别是使用STM32微控制器时,也可以找到类似的库来驱动MPU6050。STM32通常具有更强大的处理能力和更多的GPIO口,可以实现更复杂的控制算法。然而,基本的传感器操作流程和数据处理原理与Arduino平台相似。 在实际应用中,除了基本的传感器读取,还可能涉及到温度补偿、低功耗模式设置、DMP(数字运动处理器)功能的利用等高级特性。DMP可以帮助处理传感器数据,实现更高级的运动估计,减轻主控制器的计算负担。 MPU6050是一个强大的六轴传感器,广泛应用于各种需要实时运动追踪的项目中。通过 Arduino 或 STM32 的库文件,开发者可以轻松地与传感器交互,获取并处理数据,实现各种创新应用。博客和其他开源资源是学习和解决问题的重要途径,通过这些资源,开发者可以获得关于MPU6050的详细信息和实践指南
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值