Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

Locale Extend

No security coverage
View on drupal.org

This module extends Drupal Core localization system to allow translations
from different source languages, other than English.

This is a DX module, that allows development teams to build custom modules
using their own language for hardcoded strings.

Features

* It seamlessly extends t() function with a 'srclang' option. Example:

t("Hola amigo", [], ['srclang' => 'es']);

* Extends *User interface translation* form with *Source language* filter and
field.

Some API

Some static methods to translate from any source language code instead of English.

use Drupal\locale_extend\Translate;

Translate::translateFromLangcode('es')->t(...);

// Or with some static magic...

Translate::es("Hola");
Translate::de("Hallo");

Or use full TranslationInterface with predefined source language.

use Drupal\locale_extend\Translation;

Translation::fromLangcode('es')->translate(...);
Translation::fromLangcode('es')->formatPlural(...);

// Again, some static magic...
Translation::es()->formatPlural(...);

Notes for Developers

* Since it replaces Drupal core *TranslationManager* service, the extended API can be used
from anywhere, other modules are welcomed to integrate. See also warning below.

* We are extending *locales_source* table for a clean storage. The new field,
'srclang', defaults to English - en -. Thus storage is fully backwards compatible.

* For some experiments with syntactic sugar, see included submodules

See locale_extend_t, adding some shorthand function, just for es, fr, de for now...
just an experiment.

t_es("Hola amigo");
t_de("Hallo, Freund");

Or 'locale_extend_ns', using namespaces...

// Anywhere, in modules or classes.
use function Drupal\locale_extend\es\tr;
// Will translate from Spanish
tr("Hola");

More options and examples, like how to replace global 't()' function, here, https://git.drupalcode.org/sandbox/reyero-3337204/-/tree/1.0.x/modules

Coming soon

* Some extra support for configuration strings, though I'd rather have other
module handling that... ?
* An extended *StringTranslationTrait* so it also can be used in classes with a
predefined language.

@see the idea here Drupal\locale_extend\StringTranslationTrait;

Warning

This module replaces some Drupal Core services thus it may not be compatible
with other modules doing the same.

@see \Drupal\locale_extend\LocaleExtendServiceProvider

If you are a module maintainer and have a module with such issue, please let me
know, we'll find a way around it...

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Feb 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.x-dev Dev Feb 5, 2023