php drupal 8翻译

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php drupal 8翻译相关的知识,希望对你有一定的参考价值。


$langs = \Drupal::languageManager()->getLanguages();



Fortunately I found a post named Create and translate a multilingual nodes programmatically.

And here is the code with some comments:

use Drupal\node\Entity\Node;

$node = Node::create([
  // The node entity bundle in this case article.
  'type' => 'article',
  //The base language
  'langcode' => 'en',
  'created' => REQUEST_TIME,
  'changed' => REQUEST_TIME,
  // The user ID.
  'uid' => 1,
  'title' => 'My test!',
  //If you have another field lets says field_day you can do this:
  //'field_day' => 'value',
  'body' => [
    'summary' => '',
    'value' => '<p>The body of my node.</p>',
    'format' => 'full_html',
  ],
]);
//Saving the node
$node->save();
//This line is not necessary
\Drupal::service('path.alias_storage')->save("/node/" . $node->id(), "/my/path", "en");

//Creating the translation Spanish in this case
$node_es = $node->addTranslation('es');
$node_es->title = 'Mi prueba!';
$node_es->body->value = '<p>El cuerpo de mi nodo.</p>';
$node_es->body->format = 'full_html';
//Saving the node
$node_es->save();
//This line is not necessary
\Drupal::service('path.alias_storage')->save("/node/" . $node->id(), "/mi/ruta", "es");

translation views bug
https://www.drupal.org/node/2737619

以上是关于php drupal 8翻译的主要内容,如果未能解决你的问题,请参考以下文章

使用 drupal 7 翻译 node.tpl.php 文件中的字段

PHP Drupal 6:使用i18n模块翻译主要和次要链接

php 在drupal 8中找到名字: - Drupal 8

如何为自定义 Drupal 7 模块生成翻译文件?

php 在drupal 8中以编程方式创建词汇和术语: - Drupal

php Drupal 8意见结果计数。