chinleung/verbose-localization

A package to allow your class to support verbose localization.

v1.0.0 2019-08-06 19:56 UTC

This package is auto-updated.

Last update: 2024-04-07 07:24:32 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

A package to allow your class to support verbose localization.

Installation

You can install the package via composer:

composer require chinleung/verbose-localization

Usage

Add the ChinLeung\VerboseLocalization\HasVerboseLocalization trait to your class and create a method getTranslationIn(string $locale) to handle the translation of your class and get access to all the verbose methods instantly like the following example.

Suppose you have files with the translation of the text equivalent of numbers:

<?php

class NumberClass
{
    use ChinLeung\VerboseLocalization\HasVerboseLocalization;

    /**
     * Constructor of the class.
     *
     * @param  int  $value
     */
    public function __construct(int $value)
    {
        $this->value = $value;
    }

    /**
     * Retrieve the translation in a specific locale.
     *
     * @param  string  $locale
     * @return string
     */
    public function getTranslationIn(string $locale) : string
    {
        $translations = require __DIR__."/resources/lang/$locale/numbers.php";

        return $translations[$this->value];
    }
}

Then you can retrieve the translations like this:

$number = new NumberClass(1);

$number->inFrench(); // 'un'
$number->inEnglish(); // 'one'
$number->inSimplifiedChinese(); // '一'

Methods

The methods are seperated by language families which are located in src/Concerns.

Afro-Asiatic

View Methods
  • inAmharic
  • inArabic
  • inHausa
  • inHebrew
  • inMaltese
  • inSomali

Austronesian

View Methods
  • inCebuano
  • inFilipino
  • inHawaiian
  • inJavanese
  • inKhmer
  • inMalagasy
  • inMalay

Dravidian

View Methods
  • inKannada
  • inMalayalam
  • inTamil
  • inTelugu

French Creole

View Methods
  • inHaitianCreole

Hmong-Mien

View Methods
  • inHmong

Indo-European

View Methods
  • inAlbanian
  • inArmenian
  • inGreek

Balto-Slavic

View Methods
  • inBelarusian
  • inBosnian
  • inBulgarian
  • inCroatian
  • inCzech
  • inLatvian
  • inLithuanian
  • inMacedonian
  • inPolish
  • inRussian
  • inSerbian
  • inSlovak
  • inSlovenian
  • inUkrainian

Celtic

View Methods
  • inIrish
  • inScotsGaelic
  • inWelsh

Germanic

View Methods
  • inAfrikaans
  • inDanish
  • inDutch
  • inEnglish
  • inFrisian
  • inGerman
  • inIcelandic
  • inLuxembourgish
  • inNorwegian
  • inSwedish
  • inYiddish

Indo-Iranian

View Methods
  • inBengali
  • inGujarati
  • inHindi
  • inKurmanjiKurdish
  • inMarathi
  • inNepali
  • inPashto
  • inPersian
  • inPunjabi
  • inSindhi
  • inSinhala
  • inTajik
  • inUrdu

Italic

View Methods
  • inCatalan
  • inCorsican
  • inFrench
  • inGalician
  • inItalian
  • inLatin
  • inPortuguese
  • inRomanian
  • inSpanish

Isolate

View Methods
  • inBasque
  • inEsperanto

Japonic

View Methods
  • inJapanese

Kartvelian

View Methods
  • inGeorgian

Koreanic

View Methods
  • inKorean

Kra-Dai

View Methods
  • inLao
  • inThai

Monogolic

View Methods
  • Mongolian

Niger-Congo

View Methods
  • inChewa
  • inChichewa
  • inIgbo
  • inSesotho
  • inShona
  • inSwahili
  • inXhosa
  • inYoruba
  • inZulu

Sino-Tibetan

View Methods
  • inBurmeseMyanmar
  • inSimplifiedChinese
  • inTraditionalChinese

Turkic

View Methods
  • inAzerbaijani
  • inKazakh
  • inKyrgyz
  • inTurkish
  • inUzbek

Uralic

View Methods
  • inEstonian
  • inFinnish
  • inHungarian

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email hello@chinleung.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.