2017 © Pedro Peláez
 

framework localization

Alexya's Localization utilities

image

alexya-framework/localization

Alexya's Localization utilities

  • Tuesday, June 6, 2017
  • by manulaiko
  • Repository
  • 1 Watchers
  • 0 Stars
  • 17 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Localization

Alexya's localization components, (*1)

Contents

, (*2)

Text translation

The class \Alexya\Localization\Translator offers a way for translating texts. Bassically you instance a Translator object with the given text translatation and the you call the translate method whenever you want to translate a text., (*3)

, (*4)

Instantiating Translator objects

The constructor accepts as parameter an associative array containing the language code and the translations. Optionally you can send a second parameter being the default language where the texts will be translated., (*5)

Example:, (*6)

<?php
$translator = new \Alexya\Localization\Translator([
    "en" => [
        "monday"    => "monday",
        "thursday"  => "thursday",
        "wednesday" => "wednesday",
        "tuesday"   => "tuesday",
        "friday"    => "friday",
        "saturday"  => "saturday",
        "sunday"    => "sunday"
    ],
    "es" => [
        "monday"    => "lunes",
        "thursday"  => "martes",
        "wednesday" => "miercoles",
        "tuesday"   => "jueves",
        "friday"    => "viernes",
        "saturday"  => "sabado",
        "sunday"    => "domingo"
    ]
], "en");

, (*7)

Translating texts

Once the object has been instantiated you can use the method translate to translate a text. It accepts as parameter a string being the text to translate., (*8)

Optionally you can send an array with the variables to parse or a string with the language code to translate the text, or even both., (*9)

If the language doesn't exist, the text will be translated to the default language., (*10)

If the text couldn't be translated, it will return the first parameter., (*11)

Example:, (*12)

<?php
$translator = new \Alexya\Localization\Translator([
    "en" => [
        "monday"    => "monday",
        "thursday"  => "thursday",
        "wednesday" => "wednesday",
        "tuesday"   => "tuesday",
        "friday"    => "friday",
        "saturday"  => "saturday",
        "sunday"    => "sunday",

        "Today is {day}" => "Today is {day}"
    ],
    "es" => [
        "monday"    => "lunes",
        "thursday"  => "martes",
        "wednesday" => "miercoles",
        "tuesday"   => "jueves",
        "friday"    => "viernes",
        "saturday"  => "sabado",
        "sunday"    => "domingo",

        "Today is {day}" => "Hoy es {day}"
    ]
]);

// Quick translation
$translator->translate("Today is {day}");
// Today is {day}

// Translation with context
$translator->translate("Today is {day}", [
    "day" => $translator->translate("monday")
]);
// Today is monday

// Translation in a specific language
$translator->translate("Today is {day}", "es");
// Hoy es {day}

// Translation in a specific language with context
$translator->translate("Today is {day}", [
    "day" => $translator->translate("monday", "es")
], "es");
// Hoy es lunes

// Text that can't be translated
$translator->translate("some_text");
// some_text

If the language isn't specified it will be translated to the language sent to the method setDefaultLanguage., (*13)

For translating texts of a sub-array use a dot (.) to link the texts to translate:, (*14)

<?php
$translator = new \Alexya\Localization\Translator([
    "en" => [
        "days" => [
            "monday"    => "monday",
            "thursday"  => "thursday",
            "wednesday" => "wednesday",
            "tuesday"   => "tuesday",
            "friday"    => "friday",
            "saturday"  => "saturday",
            "sunday"    => "sunday"
        ],
        "phrases" => [
            "today_is" => "Today is {day}"
        ]
    ]
]);

// Recursive translation
$translator->translate("phrases.today_is", [
    "day" => $translator->translate("days.monday")
]);
// Today is monday

You can also add more translations to an already specified language with the method addTranslations. It accepts as parameter the language code and an array containing the translations to add. If the language code doesn't exist, it will create it., (*15)

The Versions

06/06 2017

dev-develop

dev-develop

Alexya's Localization utilities

  Sources   Download

GNU

The Requires

  • php >=7.1

 

by Avatar manulaiko

framework translations php locale localization php7 alexya

05/06 2017

dev-master

9999999-dev

Alexya's Localization utilities

  Sources   Download

GNU

The Requires

  • php >=7.0

 

by Avatar manulaiko

framework translations php locale localization php7 alexya

05/06 2017

3.1.0

3.1.0.0

Alexya's Localization utilities

  Sources   Download

GNU

The Requires

  • php >=7.0

 

by Avatar manulaiko

framework translations php locale localization php7 alexya

03/10 2016

3.0.3

3.0.3.0

Alexya's Localization utilities

  Sources   Download

GNU

The Requires

  • php >=7.0

 

by Avatar manulaiko

framework translations php locale localization php7 alexya

16/08 2016

3.0.2

3.0.2.0

Alexya's Localization utilities

  Sources   Download

GNU

The Requires

  • php >=7.0

 

by Avatar manulaiko

framework translations php locale localization php7 alexya

14/08 2016

3.0.1

3.0.1.0

Alexya's Localization utilities

  Sources   Download

GNU

The Requires

 

by Avatar manulaiko

framework translations php locale localization php7 alexya

14/08 2016

3.0.0

3.0.0.0

Alexya's Localization utilities

  Sources   Download

GNU

The Requires

 

by Avatar manulaiko

framework translations php locale localization php7 alexya