nolka/translation-loader-laravel

Translations loader adapter for laravel

dev-master 2020-09-30 05:41 UTC

This package is auto-updated.

Last update: 2024-04-29 04:53:25 UTC


README

This module is created for loading translations from xlsx files to Laravel translation model, and designed to work with spatie/laravel-translation-loader extension.

Description

Sometimes you need to have possibility to unload yor database strings and translate it to many languages in single file. This package was created to unload translations to these languages in single xlsx file and back, from xlsx file to database.

Translation file structure

source ru en another_lang_code
Привет, мир! Привет, мир! Hello, world! ...
validator.email_invalid Неверный e-mail Email is invalid ...

Installation

composer require nolka/translation-loader-laravel

Usage

Unload translations from database

use TranslationLoader\Laravel\Reader\DbReader;
use TranslationLoader\TranslationManager;
use TranslationLoader\Writer\XlsxWriter;

$langs = [
    'ru' => 'Russian',
    'en' => 'English',
];

$manager = new TranslationManager($langs);

$reader = new DbReader();
$exportFile = base_path() . '/to_translate.xlsx';
if (file_exists($exportFile)) {
    unlink($exportFile);
}
$writer = new XlsxWriter($manager, $exportFile);

$manager->copyTranslations($reader, $writer);

Load translations to database

use TranslationLoader\Laravel\Writer\DbWriter;
use TranslationLoader\Reader\XlsxReader;
use TranslationLoader\TranslationManager;

$langs = [
    'ru' => 'Russian',
    'en' => 'English',
];

$manager = new TranslationManager($langs);

$reader = new XlsxReader($manager, base_path() . '/translated_messages.xlsx');
$writer = new DbWriter();


$manager->copyTranslations($reader, $writer);