- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 cakephp 3.x,我想将我的网站翻译成多种语言。我阅读了有关 cakephp 3.x 国际化 ( http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html ) 的文档,它只解释了如何翻译单词和句子,而不是整页。
翻译整页文本的最佳解决方案是什么?我想做的是为每种语言创建一个页面,并在 beforeFilter 函数中选择正确的页面。这是一个好的解决方案吗?
我也在问如何翻译保存在数据库中的某些段落,例如我的新闻页面保存在数据库中,我想用不同的语言翻译我的新闻。我必须为数据库中的每种语言添加一行还是有更好的解决方案?
谢谢你的时间
丹妮
最佳答案
Internationalization & Localization有两个基本任务,在这两种情况下,您在运行时更改语言所需要做的唯一事情就是 call I18n::locale例如:
use Cake\I18n\I18n;
...
public function beforeFilter()
{
if (should show german) {
I18n::locale('de_DE');
}
}
设置完成后,无需额外步骤即可拥有多语言网站。务必set the default locale在 Bootstrap 文件中,因为如果在运行时未覆盖语言环境,则会使用它。
think to do is to have a page for each language and in the beforeFilter function, select the correct page. Is it a good solution ?
没有。
静态文件,除非您打算为每种语言或类似的页面布局完全不同,否则通常是使用 translate functions 的单个模板。和 po 文件。
来自文档:
Below is an example of some code for a single-language application:
<h2>Popular Articles</h2>
To internationalize your code, all you need to do is to wrap strings in __() like so:
<h2><?= __('Popular Articles') ?></h2>
涉及的步骤更多(请参阅文档),但对默认语言文本使用双下划线方法可以让您的应用程序准备好用于多种语言。
数据库内容通常使用 the translate behavior 翻译.
此行为将使用该行为的所有表的所有翻译内容存储在单独的表中。在运行时会自动检索翻译。举例说明:
$articles = TableRegistry::get('Articles');
I18n::locale('eng');
$article = $articles->get(12);
echo $article->title; // Echoes 'A title'
I18n::locale('spa');
$article = $articles->get(12);
echo $article->title; // Echoes 'Un titulo'
同时使用静态翻译和翻译行为,您的模板文件将如下所示:
<h1><?= h($article->title) ?></h1>
<?= $article->body ?>
<p><?= __('Did you like that article? Let us know') ?></p>
请注意,除了使用双下划线方法外,它与您对单语言应用程序的期望完全相同。
关于php - Cakephp 3.x - 国际化整页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31716409/
我有一个 Java 字符串,但在处理时遇到了问题。我有一个字符串 s,它的值为丞(我随机选择的一个汉字,我不会说中文)。如果我打电话 String t = new String(s.getBytes(
在Qt中,所有的输入部件和文本绘制方式对Qt支持的所有语言都提供了内置的支持。Qt内置的字体引擎可以在同一时间正确而且精细地绘制不同的文本,这些文本可以包含来自众多不同书写系统的字符。如果想了解更多的
如何实现字段标签、帮助文本等的国际化支持。字段的标准乘法似乎不起作用例如文档中给出的用于创建联系表单的示例。我尝试为其他语言添加额外的字段(文档中描述的第一种方法) from django.db
是否有可能当我在操作类中使用“getText(”keyName”); 时,我可以指定仅从 ENGLISH 资源包中选择值。因为我只想将此值用于日志记录目的。 任何想法我怎么能做到这一点? BR 标准委
我有一些关于 GWT 的国际化解决方法的问题。 1) 处理直接写入 ui.xml 文件的静态文本的最佳方式是什么? 目前,我正在使用 Messages-Interface 来翻译 Java 生成的文本
我在 Symfony 2 中遇到了一个奇怪的翻译问题。 这是我的config.yml imports: - { resource: parameters.yml } - { resou
对于我的大部分应用程序,我可以使用 https://developers.google.com/web-toolkit/doc/latest/DevGuideI18n 中列出的推荐国际化技术。 (主要
我使用 Android Studio 创建了一个新的 Flutter 项目。我正在使用null-safety,并且正在物理设备上运行应用程序,但代码生成无法正常工作,没有flutter_gen.dar
这里是菜鸟。 我正在尝试对基于命令行的程序实现国际化。以下是 java 国际化路径中可用的内容。 import java.util.*; public class I18NSample { s
我使用 Android Studio 创建了一个新的 Flutter 项目。我正在使用null-safety,并且正在物理设备上运行应用程序,但代码生成无法正常工作,没有flutter_gen.dar
我正在开发一个需要多语言的应用程序。 我正在尝试关注 this国际化教程。但是,当我尝试“使用基本国际化”时, View 中没有列出我的 Storyboard。 我正在使用 XCode 4.6.3 我
我住在印度(有超过20种语言)我正在尝试在网站中实现java国际化。 但是在 Locale.getAvailableLocales() 中,本地语言不可用。我的情况是否可以实现国际化? 如果可能的话字
我有以下 SDN 4 实体: 决策、特征和值: @NodeEntity public class Value { private final static String SET_FOR = "
关于MySql,是否有支持所有或绝大多数语言的字符集? 最佳答案 统一码。它有几种编码:UTF-8、UTF-16 和 UTF-32。 来自 http://en.wikipedia.org/wiki/U
我目前正在使用 Vuepress。但是我想要在我的 Vuepress 站点中使用多种语言。经过 3 天的挣扎,我决定把我的问题放在这里。 (是的,我查看了 Vuepress 文档:https://vu
我需要返回一个 strftime() 调用,该调用使用与我本地机器/操作系统上设置的语言不同的语言。是否可以选择返回语言? 最佳答案 对于可靠的 i18n/L10N,可由必须在同一运行中提供不同本地化
我有一些按钮,按下它们后我想播放一些音频。按钮的名称是音频文件的名称 private func playAudio(title : String){ audioPlayer = AVAudio
如何更改 HTML5 的消息(或者它会根据浏览器的语言自动更改?) 例如: E-mail: 当我在 Opera 运行此代码(来自 W3schools)
我发现很多关于 url schemes 的话题,最常见的是: www.mysite.com/fr/products www.mysite.com/en/products www.mysite.com/
在 Android WebView 中处理国际化/本地化的最佳方式是什么。理想情况下,我想访问以下位置的所有字符串资源: res/values/strings.xmlres/values-de/str
我是一名优秀的程序员,十分优秀!