2017 © Pedro Peláez
 

joomla-package language

Joomla Language Package

image

joomla/language

Joomla Language Package

  • Saturday, July 14, 2018
  • by mbabker
  • Repository
  • 11 Watchers
  • 3 Stars
  • 5,661 Installations
  • PHP
  • 12 Dependents
  • 1 Suggesters
  • 11 Forks
  • 3 Open issues
  • 16 Versions
  • 6 % Grown

The README.md

The Language Package Build Status

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Usage

Prepare language files

Let's say you want to use English (UK) language pack., (*2)

You may find helpful some files distributed with Joomla CMS:, (*3)

  • en-GB.ini - Common language strings such as JYES, ERROR, JLOGIN.
  • en-GB.lib_joomla.ini - Application language strings like JLIB_APPLICATION_SAVE_SUCCESS ('Item successfully saved.').
  • en-GB.localise.php - To use language-specific methods like getIgnoredSearchWords.
  • en-GB.xml - To use Language metadata definitions (full name, rtl, locale, firstDay).

In the Framework version 1.* Language handler loads language files from directory defined by JPATH_ROOT . '/languages/[language tag]/, (*4)

In the example below, we will additinally load your application language strings located in file en-GB.application.ini., (*5)

Prepare configuration

Assuming configuration in a JSON format:, (*6)

{
    "lang": "en-GB",
    "debug": true
}

Set up the Language instance in Web application

In the example below comments in language tag are replaced by xx-XX, (*7)

use Joomla\Application\AbstractWebApplication;
use Joomla\Language\Language;
use Joomla\Language\Text;

class MyApplication extends AbstractWebApplication
{
    protected $language;

    protected function initialise()
    {
        parent::initialise();

        $language = $this->getLanguage();

        // Load xx-XX/xx-XX.application.ini file
        $language->load('application');
    }

    /**
     * Get language object.
     *
     * @return  Language
     *
     * @note    JPATH_ROOT has to be defined.
     */
    protected function getLanguage()
    {
        if (is_null($this->language))
        {
            // Get language object with the lang tag and debug setting in your configuration
            // This also loads language file /xx-XX/xx-XX.ini and localisation methods /xx-XX/xx-XX.localise.php if available
            $language = Language::getInstance($this->get('language'), $this->get('debug'));

            // Configure Text to use language instance
            Text::setLanguage($language);

            $this->language = $language;
        }

        return $this->language;
    }
}

Use Text methods

namespace App\Hello\Controller;

use Joomla\Language\Text
use Joomla\Controller\AbstractController;

class HelloController extends AbstractController
{
    public function execute()
    {
        $app = $this->getApplication();

        $translatedString = Text::_('APP_HELLO_WORLD');

        $app->setBody($translatedString);
    }
}

Using Text From Twig

If you are using Twig as a templating engine you will be unable to execute PHP code in the layout to use the Text magic function directly. One option is to add each string to the view, however you can also use Twig functions., (*8)

Creating a Twig function will allow the use of syntax like the below in your layout file., (*9)

jtext('APP_YOURSAMPLE_STRING')

To create a Twig function to do this after creating the Twig_Environment and before rendering add the following code:, (*10)

$loader = new \Twig_Loader_Filesystem($this->path);
$twig = new \Twig_Environment($loader);

$jtextFunction = new \Twig_SimpleFunction('jtext',function($string){
    $translation = Text::_($string);
    return $translation;
},array('is_safe'=>array('html')));

$twig->addFunction($jtextFunction);

You will now be able translate strings in your twig file using:, (*11)

{{jtext('APP_YOURSAMPLE_STRING')}}

Load component language files

@TODO, (*12)

Installation via Composer

Add "joomla/language": "~1.0" to the require block in your composer.json and then run composer install., (*13)

{
    "require": {
        "joomla/language": "~1.0"
    }
}

Alternatively, you can simply run the following from the command line:, (*14)

composer require joomla/language "~1.0"

If you want to include the test sources and docs, use, (*15)

composer require --prefer-source joomla/language "~1.0"

The Versions

14/07 2018

dev-2.0-dev

dev-2.0-dev https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

 

The Development Requires

framework language joomla

30/06 2018

dev-master

9999999-dev https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

 

The Development Requires

framework language joomla

06/04 2018

dev-extract-loader

dev-extract-loader https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

framework language joomla

15/03 2018

1.4.0

1.4.0.0 https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

framework language joomla

18/02 2018

dev-drop-default

dev-drop-default https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

framework language joomla

30/01 2016

1.3.0

1.3.0.0 https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

09/02 2015

1.2.0

1.2.0.0 https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

29/10 2014

1.1.3

1.1.3.0 https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

23/08 2014

1.1.2

1.1.2.0 https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

09/02 2014

1.1.1

1.1.1.0 https://github.com/joomla-framework/language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

18/01 2014

1.1.0

1.1.0.0 https://github.com/joomla/joomla-framework-language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

05/11 2013

1.0

1.0.0.0 https://github.com/joomla/joomla-framework-language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

22/10 2013

1.0-beta3

1.0.0.0-beta3 https://github.com/joomla/joomla-framework-language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

16/08 2013

1.0-beta2

1.0.0.0-beta2 https://github.com/joomla/joomla-framework-language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

16/08 2013

1.0-beta

1.0.0.0-beta https://github.com/joomla/joomla-framework-language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla

04/06 2013

1.0-alpha

1.0.0.0-alpha https://github.com/joomla/joomla-framework-language

Joomla Language Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework language joomla