Skip to content
translatable / v1

Adding Languages

How to add and remove locales allowed for translations

Last updated:

On this page

Translatables will only work once allowed languages are added.

Adding an allowed language

To add a language that is allowed to translate to, just simply add to the model that is used in language_model in your config/translatable.php file. The code below will work if the language_model is kept as it's default value.

use Javaabu\Translatable\Models\Language;

...

Language::create([
    'name' => 'English',
    'code' => 'en',
    'locale' => 'en',
    'flag' => '🇬🇧',
    'is_rtl' => false,
    'active' => true,
]);

The code field will be used internally while the locale field will be what is set to the html lang attribute. The is_rtl attribute controls whether this language is meant to be shown right-to-left.

Warning

If your code contains an underscore (_), using the lang suffixes (attr_en) may not work as expected, please use a - if necessary.

Danger

When adding allowed languages, please note that by default, the default_locale will not be allowed as no language_model record exists for it. Ensure you have added the default_locale language for translatables to work as intended.

Deleting an allowed language

To soft-delete a language, you can simply set the active to false.

$lang_en = \Javaabu\Translatable\Facades\Languages::get('en');

$lang_en->active = false;
$lang_en->save();

To completely remove a language, you can delete the language record.

Warning

Note that this does not delete the existing language records on a translatable model.

\Javaabu\Translatable\Facades\Languages::get('en')->delete();
Documentation
All packages

javaabu/translatable

Source on GitHub