Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Translation

By editor , 30 September, 2021

Translation API - PHP Twig JavaScript

Tags

  • Drupal 8
  • Drupal 9
  • Translation
  • JavaScript
  • Twig
  • PHP

PHP Class using StringTranslationTrait

StringTranslationTrait allow to get t() and formatPlural() methods
Example:
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
class MyClass {

By editor , 23 December, 2015

Delete a source string and the target translations in Drupal 8

Tags

  • Drupal 8
  • Code
  • Translation

As you haven't a Delete button on interface translation page, you can't do that from the translation interface. But you can do in a small custom module.

Example : Delete string ID 346, 'Home'

      $lid = 346;

By editor , 1 December, 2015

Get all languas of the site in Drupal 8

Tags

  • Drupal 8
  • Code
  • Translation

To get languages in English:
$site_languages = \Drupal::languageManager()->getLanguages();

To get languages in native language:
$site_languages = \Drupal::languageManager()->getNativeLanguages();

By editor , 28 November, 2015

Create and translate a multilingual nodes programmatically.

Tags

  • Drupal 8
  • Code
  • Translation
  • Node

Programmatically create and translate nodes.

By editor , 28 November, 2015

Translate a node programmatically

Tags

  • Drupal 8
  • Code
  • Translation
  • Node

Exemples:

$translation = $entity->getTranslation('de');

By editor , 6 November, 2015

How to get the current language in Drupal 8

Tags

  • Drupal 8
  • Code
  • Translation
  • User

Drupal 8

//To get the lanuage code:
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();

//To get the language name:
$language =  \Drupal::languageManager()->getCurrentLanguage()->getName();

Translation

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer