'Most active poster in, array ( => $forum -> name ) The most common placeholder is probably This placeholder runs static::placeholderEscape() on the text before replacing it. ![]() You use a placeholder to insert a value into the translated text, like in this example from the Advanced Forum contrib module: Placeholders come from the placeholderFormat method, which is called during the translation render() method. You can read more about string context ’s String Context documentation. For many languages, the string "Order" needs a different translation for each of these meanings. This is a problem when one English word has several meanings, like "Order", which can mean the order of elements in a list, to order something in a shop, or an order someone has placed in a shop. When translating Drupal’s user interface to other languages, each original (English) string can have only one translation. String context (or translation context) is a way to organize translations when words have one to many translations. * 'context' (defaults to the empty context): A string giving the context that the source string belongs to. * 'langcode' (defaults to the current language): The language code to translate to a language other than what is used to display the page. The third is an array of options.įrom : $options: An associative array of additional options, with the following elements: The first is the string to be translated, the second is the array of replacements, if any. The t() function takes three parameters, two of which are optional. Depending on which placeholder you use, it runs different sanitization functions. ![]() What does it do?įirstly, t() translates text at runtime if you have more than one language enabled. You might be thinking "oh, this string will never need to be translated," but two years later, when you’re trying to find this string that’s showing up untranslated on the site, and your stakeholders want it changed, you’ll be much happier if it’s already ready to translate. This ensures that your site can be localized! When in doubt, translate everything. Additional details can be found in the Translation API documentation. Often times the t() and formatPlural() methods are often already available when extending common Drupal base classes for controllers and plugins, reducing the need to add traits or inject the service in custom classes. The StringTranslationTrait is also available to simplify the inclusion of the t() function and other translation methods in classes. While this function is still available in Drupal 8, with the switch to a services architecture, it is now best practice to use the TranslationManager class (the string_translation service). When coding, you wrap your user-facing strings in this function so that they can be translated. In procedural code, the t() function allows for localization and translates a given string to a given language at run-time. Drupal 8 uses the Translation API whereas Drupal 7 and earlier versions use the Localization API User interface text that is written in code must be prepared in a special way in order for the interface text to be identified and translated properly. Drupal Code Standards: Twig in Drupal 8.Drupal Code Standards: Object Oriented Coding & Drupal 8.Drupal Code Standards: The t() function.Drupal Code Standards: How Do We Implement Them?.This is so essential that it deserves its own post! Other posts in this series: ![]() In this post we’ll talk about how to use translation functions in both Drupal 7 and 8. This is the fifth post in a series about coding standards.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |