Skip to content

i18n ​

File: src/Helpers/i18n.php

Internationalization and translation helpers that extend Laravel's built-in trans() with Modularous-specific JSON fallback, label resolution, and Vue store formatting.

Functions ​

modularousTrans ​

php
modularousTrans(string $key, array $replace = [], string $locale = null): string

Looks up a translation key in the modularous:: namespace. Returns the raw key if no translation is found, making missing keys visible rather than silently empty.


___ (triple underscore) ​

php
___(string $key, array $replace = [], string $locale = null): string

The primary Modularous translation helper. Resolution order:

  1. trans($key) — standard Laravel lookup
  2. trans("{$module}::{$key}") — module-namespaced lookup
  3. JSON translation files for the active locale
  4. Returns $key unchanged if nothing matches

Use ___ instead of __ throughout Modularous controllers and views.


hasUnusualTrans ​

php
hasUnusualTrans(string $key): bool

Returns true if the given key resolves to a different string than the key itself — i.e. a real translation exists.


trans_replacements ​

php
trans_replacements(string $translation, array $replacements): string

Applies [':KEY' => $value] replacements to an already-translated string. Thin wrapper over Laravel's str_replace replacement pattern.


getLabelFromLocale ​

php
getLabelFromLocale(string $key, string $locale = null): string

Retrieves the label for $key from the locale-specific translation file rather than the active app locale. Useful for generating labels in a target language during export or email generation.


getCode2LanguageTexts ​

php
getCode2LanguageTexts(): array

Returns the full ISO 639-1 language code → language name map as an array (e.g. ['en' => 'English', 'tr' => 'Turkish', ...]). Used to populate language selector dropdowns.


getLanguagesForVueStore ​

php
getLanguagesForVueStore(): array

Returns the active application locales formatted for the Vuex/Pinia store:

php
[
    ['code' => 'en', 'label' => 'English'],
    ['code' => 'tr', 'label' => 'Turkish'],
    // ...
]

Only includes locales listed in config('translatable.locales').