Translation UI for Locale Extend

This project is not covered by Drupal’s security advisory policy.

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...

Supporting organizations: 

Project information

Releases