Giter Club home page Giter Club logo

jphp-localization-ext's Introduction

Localization Extension for JPHP

Installation

jppm add localization@git+https://github.com/GIGNIGHT/jphp-localization-ext

Documentation

How to usage?

<?php
# Import classes
# Or using package "localization"
use bundle\gignight\Localization;
use bundle\gignight\exception\LocalizationException;
use bundle\gignight\exception\LocalizationFileNotFoundException;

try
{
    # Specify a short language code
    $languageCode = 'ru';
    
    # Creating a new localization file
    $lFile = new \bundle\gignight\LocalizationFile("lang/{$languageCode}");
    
    # Init localization
    $localization = new Localization($lFile); # Or $languageCode
    
    # Example write lines
    $localization->set('ThISiS.ExamPle.Key', 'Hello World') # The name of the key can be any register
                 ->set('account.user.welcome', "Hello, %s! You are %d years old?") # Supports string formatting
                 ->set('app.name', 'Test')
                 ->set('...', '')
                 ->save(); 
                 
    # Alternative
    $config = array
    (
      'key'      => '123',
      'app.name' => 'Test'
    );
    
    $localization->setAll($config);


    # Getting
    $localization->get('account.user.welcome', 'User', 20); # Return "Hello, User! You are 20 years old?"
    $localization->get('key'); # "123"
    $localization->get('app.name'); # "Test"
    
    # Or using Helper (Global Function)
    var_dump(__('app.name'));
}
catch (LocalizationException | LocalizationFileNotFoundException $e)
{
    Logger::error($e->getMessage());
}

jphp-localization-ext's People

Contributors

gignight avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.