A convenience package for php multilingual web applications

Overview

PHP Translation

It is a php package that enables multi-language capability very easily. Also, the package accepts formats as array, json and Database.

Install

    composer require ahmetbarut/translation

Lifecycle

diagram

Configuration

The directory structure of the language files should be as follows and it should return an array. The location of the directory is not important, but the content is!


  • lang
    • en
      • menu.php / menu.json
    • tr
      • menu.php / menu.json
    • de
      • menu.php / menu.json

Content of PHP File

    return [
    'home' => 'Home',
];

Content of Json File

    {
        "home": "Home",
        "deneme": "TEST"
    }

Content Of Database Table

You can change the table name as you wish. If the table name is different, you must give the table name to the $table parameter in the constructor of the Translation class.

CREATE TABLE translation (
    id serial PRIMARY KEY,
    key varchar (255),
    value VARCHAR (255),
    language VARCHAR(255)
    )

Use Of

Array Or Json

setLocale('en'); trans('menu.home') ">
use ahmetbarut\Translation\Translation;

require "./vendor/autoload.php";

$translation = new Translation(__DIR__ . '/lang', 'array');
$translation->setLocale('en');

trans('menu.home')

The trans function accepts a string and the first word before the period represents the file, and the word after the period is the key to the requested value.

The setLocale method also belongs to the Translation class.

Database

getMessage()); } $translation = new Translation( format: 'db', connect: $connect, table: 'translation_words'); $translation->setLocale('en'); trans('home') ">
use ahmetbarut\Translation\Translation;

require "./vendor/autoload.php";

try {
    $connect = new PDO('pgsql:host=localhost;dbname=translation;', 'ahmetbarut', "");
}catch (PDOException $th){
    die($th->getMessage());
}

$translation = new Translation( format: 'db', connect: $connect, table: 'translation_words');
$translation->setLocale('en');

trans('home')

The trans function does not expect . in this case.

You might also like...
Official PHP library for the DeepL language translation API.

deepl-php Official PHP client library for the DeepL API. The DeepL API is a language translation API that allows other computer programs to send texts

A PHP internationalization library, powered by CLDR data.

intl A PHP 7.1+ internationalization library, powered by CLDR data. Features: NumberFormatter and CurrencyFormatter, inspired by intl. Currencies Lang

FBT - a internationalization framework for PHP designed to be not just powerful and flexible, but also simple and intuitive
FBT - a internationalization framework for PHP designed to be not just powerful and flexible, but also simple and intuitive

FBT is an internationalization framework for PHP designed to be not just powerful and flexible, but also simple and intuitive. It helps with the follo

A set of PSR-7 object decorators providing useful convenience methods

Slim-Http Slim PSR-7 Object Decorators Installation It's recommended that you use Composer to install this library. $ composer require slim/http This

[Deprecated] A Laravel package for multilingual models
[Deprecated] A Laravel package for multilingual models

This package has been deprecated. But worry not. You can use Astrotomic/laravel-translatable. Laravel-Translatable If you want to store translations o

A Laravel package for multilingual models
A Laravel package for multilingual models

Introduction If you want to store translations of your models into the database, this package is for you. This is a Laravel package for translatable m

A Concrete CMS package to add interfaces to translate multilingual content. You can translate content manually, or use cloud API.

Concrete CMS add-on: Macareux Content Translator Concrete CMS has powerful features to manage multilingual content by its default. You can add languag

Multilingual PHP CMS built with Laravel  and bootstrap
Multilingual PHP CMS built with Laravel and bootstrap

Lavalite This is an open source of Content Management System developed with Laravel framework. Documentation Visit Documentation section in the websit

A multilingual, extensible, community oriented CMS developed in PHP
A multilingual, extensible, community oriented CMS developed in PHP

ImpressCMS is a community developed Content Management System. With this tool maintaining the content of a website becomes as easy as writing a word d

Multilingual PHP CMS built with Laravel  and bootstrap
Multilingual PHP CMS built with Laravel and bootstrap

Lavalite This is an open source of Content Management System developed with Laravel framework. Documentation Visit Documentation section in the websit

A multilingual, extensible, community oriented CMS developed in PHP
A multilingual, extensible, community oriented CMS developed in PHP

ImpressCMS is a community developed Content Management System. With this tool maintaining the content of a website becomes as easy as writing a word d

Easy multilingual urls and redirection support for the Laravel framework

Linguist - Multilingual urls and redirects for Laravel This package provides an easy multilingual urls and redirection support for the Laravel framewo

Multilingual CMS built with Laravel.
Multilingual CMS built with Laravel.

TypiCMS TypiCMS is a modular multilingual content management system built with Laravel. Out of the box you can manage pages, events, news, places, men

Multilingual CMS built with Laravel.
Multilingual CMS built with Laravel.

TypiCMS TypiCMS is a modular multilingual content management system built with Laravel. Out of the box you can manage pages, events, news, places, men

Polymorphic and Multilingual CMS powered by Laravel

Nuclear CMS Polymorphic and multilingual content management system. Nuclear is a polymorphic and multilingual content management system powered by Lar

Get estimated read time of an article. Similar to medium.com's "x min read". Multilingual including right-to-left written languages. Supports JSON, Array and String output.

Read Time Calculates the read time of an article. Output string e.g: x min read or 5 minutes read. Features Multilingual translations support. Static

A modular multilingual CMS built with Laravel 5.

AsgardCMS Platform View the documentation at AsgardCMS.com/docs. Join the conversation on Slack License The AsgardCMS is open-sourced software license

Trait for multilingual resource file support

⚡ Usage This library supports MultilingualResourceTrait which can be used in PluginBase. Multilingual support of resource files is possible using this

Trait for multilingual resource file support

⚡ Usage This library supports MultilingualResourceTrait which can be used in PluginBase. Multilingual support of resource files is possible using this

Releases(v1.1.0)
Owner
Ahmet Barut
Ahmet Barut
Easy multilingual urls and redirection support for the Laravel framework

Linguist - Multilingual urls and redirects for Laravel This package provides an easy multilingual urls and redirection support for the Laravel framewo

Tanel Tammik 189 Jul 18, 2022
Trait for multilingual resource file support

⚡ Usage This library supports MultilingualResourceTrait which can be used in PluginBase. Multilingual support of resource files is possible using this

PocketMine-MP projects of PresentKim 1 Jun 7, 2022
Composer package providing translation features for PHP apps

PHP translation This is a composer package providing translation support for PHP applications. It is similar to gettext, in usage, with these differen

Sérgio Carvalho 0 Aug 15, 2022
Package to manage Laravel translations locally

Translation Manager For Laravel Easy to use package that helps you with the translation of your Laravel application locally. Features ✅ Check all loca

null 5 Jan 8, 2022
pH7CMS Internationalization package.

?? pH7CMS Internationalization (I18N) package ?? Get new languages for your pH7CMS website!

pH7 Social Dating CMS (pH7CMS) 18 Oct 5, 2022
This package allows to translate text using Google Translator for free without api.

Text Translator for PHP This package allows text translation using Google Translate for free without an API. It extracts the translated text from the

The Jano 3 Nov 7, 2022
PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)

Gettext Note: this is the documentation of the new 5.x version. Go to 4.x branch if you're looking for the old 4.x version Created by Oscar Otero http

Gettext 651 Dec 29, 2022
Patchwork UTF-8 for PHP: Extensive, portable and performant handling of UTF-8 and grapheme clusters for PHP

Patchwork UTF-8 for PHP Patchwork UTF-8 gives PHP developpers extensive, portable and performant handling of UTF-8 and grapheme clusters. It provides

Nicolas Grekas 80 Sep 28, 2022
A morphological solution for Russian and English language written completely in PHP.

Morphos A morphological solution for Russian and English language written completely in PHP. Tests & Quality: Features [✓] Inflection of Personal name

Sergey 723 Jan 4, 2023
Geographer is a PHP library that knows how any country, state or city is called in any language

Geographer Geographer is a PHP library that knows how any country, state or city is called in any language. Documentation on the official website Incl

Menara Solutions 757 Nov 24, 2022