Start Translate - Logaty

Start Translation

When you think about translating your content, you may think about the page “title” and “body”. However, fully translated content requires more attention. In this document, we explain what you need to know to starting translate your content in your sites.

Files Structure

setup files to translation

the language directory in (./local/languages/). in this directory you must create one directory each language in your website. you can change language directory from configuration.

Initialization

Beginning Translate
in my case i want to create website with 2 languages (English, Arabic).

  • Create Languages Directories

    inside -local/languages- directory I want to create (Arabic, English) directories

    • languages
      • en
      • ar
  • Create Translation Files

    inside each -languages directories- I want to create translation files for homepage content

    • languages
      • en
        • home.php
      • ar
        • home.php
  • set translation files content

    translation files return an array has a sentence key and translation.

    ar/home.php
    <?php
        return [
            'welcome'      => 'مرحبا بك في الصفحة الرئيسية للغاتي.',
            'description' => 'لغاتي هي مكتبة لتعدد اللغات, تسمح لك بتطوير موقعك القادم بعدة لغات بكل سهولة'
        ];
    
    
    en/home.php
    <?php
        return [
            'welcome'      => 'Welcome to Logaty Home Page.',
            'description' => 'Logaty its Multi Language Library which can help you rapidly develop your next Multilingual Website'
        ];
    
    
  • Now Create all translation files your website need

    now you can create all translation you need in your website.
    Remember you can add unlimited languages in your website.

Get Translation

get correct translation as selected language
last thing we need to get translation as language visitor selected.

you have 3 ways to get translation.

echo logaty()->_x('translation-file.translation-key')
logaty()->__('translation-file.translation-key')

to return to our example

<?php
    // as selected language
    /* 1 */ echo logaty()->_x('home.welcome');
    /* 2 echo directly */ logaty()->__('home.welcome');

    // as given language parameter
    /* 1 */ echo logaty()->_x('home.welcome', 'ar');
    /* 2 echo directly */ logaty()->__('home.welcome', 'en');


output well be as selected language if second parameter not set.

<?php
    echo logaty()->_x('home.welcome');
    /** Output :
        * if selected language is (arabic) : مرحبا بك في الصفحة الرئيسية للغاتي.
        * if selected language is English  : Welcome to Logaty Home Page.
    */

    /** --------------- Force Translation Language ---------------- */
     echo logaty()->x('home.welcome', 'en');
    /** Output :
        * if selected language is (arabic) :  Welcome to Logaty Home Page.
        * if selected language is English  : Welcome to Logaty Home Page.
    */