Drupal API - t()

所属文件 includes/common.inc

 

这个函数的主要功能就是把代码中需要翻译的英文翻译成本地语言, 并提供格式化功能方便在页面上显示. 需要注意的是在安装过程中要使用 st() 代替 t() , 系统提供了 get_t() 返回当前应该使用那个 t() 

 

下面是API中的函数文档

 

Translate strings to the page language or a given language.
把文本翻译成和页面设置的语言或特定的语言.

 

Human-readable text that will be displayed somewhere within a page should be run through the t() function.
通过这个方法可以得到便于阅读并能够在页面上显示的文本.

 

Examples:

 

 

 

Any text within t() can be extracted by translators and changed into the equivalent text in their native language.
函数 t 能使用本地语言翻译任何文本

 

Special variables called "placeholders" are used to signal dynamic information in a string which should not be translated. Placeholders can also be used for text that may change from time to time (such as link paths) to be changed without requiring updates to translations.
在文本中可以使用"占位符"来标识不需要翻译的"动态信息"(如网站的在线人数), 还可以用"占位符"来标识那些内容很少变动,即使发生变化也不会影响理解的"动态信息"

 

 

For example:

 

 

There are three styles of placeholders:
占位符有3种表现形式:

  • !variable, which indicates that the text should be inserted as-is. This is useful for inserting variables into things like e-mail
    !variable, 在 t() 代码实现中直接调用了 php 函数 strtr(). 在需要在文本中插入诸如 email 等数据时这种模式会很有效.

  • @variable, which indicates that the text should be run through check_plain, to escape HTML characters. Use this for any output that's displayed within a Drupal page.
    @variable, 对文字中包含的特殊字符进行编码,使其能够在页面上正常显示. 推荐使用这种模式在 Drupal 页面上显示文本.

  • %variable, which indicates that the string should be HTML escaped and highlighted with theme_placeholder() which shows up by default as <em>emphasized</em>.
    %variable, 对文字中包含的特殊字符进行编码并可以包含样式在页面上突出显示, 默认的样式使用<em></em>

 

 

When using t(), try to put entire sentences and strings in one t() call. This makes it easier for translators, as it provides context as to what each word refers to. HTML markup within translation strings is allowed, but should be avoided if possible. The exception are embedded links; link titles add a context for translators, so should be kept in the main string.
当使用 t() 时应该传入整句或整段的文本以确保得到正确的结果, 并且虽然 t() 支持 HTML 标记,但也应当尽量避免在文本中包含它们. 

 

Here is an example of incorrect usage of t():
这是一个使用不当的例子, 文本中的 HTML 链接会被当成内容直接显示出来:

 

Here is an example of t() used correctly:
这是正确的使用方法:

 

Avoid escaping quotation marks wherever possible.
避免在文本转义引号

Incorrect:
错误的:

Correct:
正确的:

 

Because t() is designed for handling code-based strings, in almost all cases, the actual string and not a variable must be passed through t().
由于 t() 被设计成处理 code-based strings, 所以在大多数情况下要翻译的文本必须直接传递给 t(), 不能通过一个变量来传递.

Extraction of translations is done based on the strings contained in t() calls. If a variable is passed through t(), the content of the variable cannot be extracted from the file for translation.
翻译过程是建立在 t() 的调用过程中包含文本的基础上的, 如果把一个变量传递给 t() , t() 就无法把变量指向的文本从文件中提取出来做翻译.

Incorrect:
错误的:

Correct:
正确的:

The only case in which variables can be passed safely through t() is when code-based versions of the same strings will be passed through t() (or otherwise extracted) elsewhere.
只有一种情况可以安全的使用变量,那就是变量所指向的文本在其它地方以直接方式调用过 t()

In some cases, modules may include strings in code that can't use t() calls. For example, a module may use an external PHP application that produces strings that are loaded into variables in Drupal for output. In these cases, module authors may include a dummy file that passes the relevant strings through t(). This approach will allow the strings to be extracted.
有是模块需要输出指向外部代码的文本变量, 这是不能直接使用 t() 必须通过引用一个包含相关文本的 dummy file 来实现.

Sample external (non-Drupal) code:
外部代码示例:

Sample dummy file:
dummy file 示例: 

Having passed strings through t() in a dummy function, it is then okay to pass variables through t(). 
在 dummy function 中传递真实文本到 t() 以后就是可以在 t() 调用过程中使用相关的变量了.

However tempting it is, custom data from user input or other non-code sources should not be passed through t(). Doing so leads to the following problems and errors:
无论什么时候用户输入的自定义数据和 non-code sources  都不要使用 t() 做翻译, 这样做会出现下面描述的问题和错误:

  • The t() system doesn't support updates to existing strings. When user data is updated, the next time it's passed through t() a new record is created instead of an update. The database bloats over time and any existing translations are orphaned with each update.
    翻译系统不支持更新已经存在的文本. 当用户数据更新后再次使用 t() 翻译, 翻译系统会保存一份新的翻译纪录并不会更新原有记录. 保存在数据库中翻译数据会随着每次更新不断的膨胀.
  • The t() system assumes any data it receives is in English. User data may be in another language, producing translation errors.
    翻译系统只能对英文文本做翻译, 用户数据可能用的是其它语言,这样会导致翻译错误.
  • The "Built-in interface" text group in the locale system is used to produce translations for storage in .po files. When non-code strings are passed through t(), they are added to this text group, which is rendered inaccurate since it is a mix of actual interface strings and various user input strings of uncertain origin.
    在本地化系统中 "Built-in interface" 组是用来保存那些存储在 .po 文件中的译文数据. 传递到 t() 中的 non-code strings 也会保存到这个组中, 当用户输入与内置接口文本发生混淆时会造成翻译错误.

Incorrect:
错误的:

Instead, translation of these data can be done through the locale system, either directly or through helper functions provided by contributed modules.
正确的方法是使用 locale system, 也可以使用发布模块提供的相关方法. 

 

Parameters

$string A string containing the English string to translate.

$args An associative array of replacements to make after translation. Incidences of any key in this array are replaced with the corresponding value. Based on the first character of the key, the value is escaped and/or themed:

  • !variable: inserted as is
  • @variable: escape plain text to HTML (check_plain)
  • %variable: escape text and theme as a placeholder for user-submitted content (check_plain + theme_placeholder)

$langcode Optional language code to translate to a language other than what is used to display the page.

Return value

The translated string.

内容概要:本文档是一份关于交换路由配置的学习笔记,系统地介绍了网络设备的远程管理、交换机与路由器的核心配置技术。内容涵盖Telnet、SSH、Console三种远程控制方式的配置方法;详细讲解了VLAN划分原理及Access、Trunk、Hybrid端口的工作机制,以及端口镜像、端口汇聚、端口隔离等交换技术;深入解析了STP、MSTP、RSTP生成树协议的作用与配置步骤;在路由部分,涵盖了IP地址配置、DHCP服务部署(接口池与全局池)、NAT转换(静态与动态)、静态路由、RIP与OSPF动态路由协议的配置,并介绍了策略路由和ACL访问控制列表的应用;最后简要说明了华为防火墙的安全区域划分与基本安全策略配置。; 适合人群:具备一定网络基础知识,从事网络工程、运维或相关技术岗位1-3年的技术人员,以及准备参加HCIA/CCNA等认证考试的学习者。; 使用场景及目标:①掌握企业网络中常见的交换与路由配置技能,提升实际操作能力;②理解VLAN、STP、OSPF、NAT、ACL等核心技术原理并能独立完成中小型网络搭建与调试;③通过命令示例熟悉华为设备CLI配置逻辑,为项目实施和故障排查提供参考。; 阅读建议:此笔记以实用配置为主,建议结合模拟器(如eNSP或Packet Tracer)动手实践每一条命令,对照拓扑理解数据流向,重点关注VLAN间通信、路由选择机制、安全策略控制等关键环节,并注意不同设备型号间的命令差异。
多旋翼无人机组合导航系统-多源信息融合算法(Matlab代码实现)内容概要:本文围绕多旋翼无人机组合导航系统,重点介绍了基于多源信息融合算法的设计与实现,利用Matlab进行代码开发。文中采用扩展卡尔曼滤波(EKF)作为核心融合算法,整合GPS、IMU(惯性测量单元)、里程计和电子罗盘等多种传感器数据,提升无人机在复杂环境下的定位精度与稳定性。特别是在GPS信号弱或丢失的情况下,通过IMU惯导数据辅助导航,实现连续可靠的位姿估计。同时,文档展示了完整的算法流程与Matlab仿真实现,涵盖传感器数据预处理、坐标系转换、滤波融合及结果可视化等关键环节,体现了较强的工程实践价值。; 适合人群:具备一定Matlab编程基础和信号处理知识,从事无人机导航、智能控制、自动化或相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于多旋翼无人机的高精度组合导航系统设计;②用于教学与科研中理解多传感器融合原理与EKF算法实现;③支持复杂环境下无人机自主飞行与定位系统的开发与优化。; 阅读建议:建议结合Matlab代码与理论推导同步学习,重点关注EKF的状态预测与更新过程、多传感器数据的时间同步与坐标变换处理,并可通过修改噪声参数或引入更多传感器类型进行扩展实验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值