Coder Social home page Coder Social logo

translate's Introduction

Translate Build Status Coverage Status

Minimalistic yet powerful high performance message localization PHP 7.1+ component not only for Nette framework

composer require rostenkowski/translate

Translations

Translations are stored by default in *.neon files in this format:

# simple message
Welcome!: Vítejte!

# with placeholder
Hi %s!: Ahoj %s! 

# multiple forms
You have %s points.: 
  - Máte %s bod.
  - Máte %s body.
  - Máte %s bodů.

Usage with Nette Framework

Put your translations to %appDir%/translations directory as cs_CZ.neon etc.

# register extension
extensions:
  translate: Rostenkowski\Translate\Extension
  
# configuration
translate:
  default: cs_CZ

Advanced options

You can use special plural form for the count of 0 (zero). In translation source file you can define this form under special index -1.

"%s problems detected":
  -1: "No problem detected"
  - "%s problem detected" 
  - "%s problems detected" 
$translator->useSpecialZeroForm = true;
$translator->translate('%s problems detected', 0);
// "No problem detected" instead of "0 problems detected"

Usage with plain PHP

<?php

namespace App;

require __DIR__ . '/vendor/autoload.php';

use Rostenkowski\Translate\Translator;
use Rostenkowski\Translate\NeonDictionary\NeonDictionaryFactory;

// both translations and cache are in the same directory
$translator = new Translator(new NeonDictionaryFactory(__DIR__, __DIR__));
$translator->setLocale('cs_CZ');
$translator->translate('Welcome!');

Requirements

  • PHP 7.1+
  • nette/di
  • nette/neon
  • nette/safe-stream
  • nette/utils
  • nette/tester

Contributing

# run tests
vendor/bin/tester -c tests/php.ini tests/

# code coverage report (requires xdebug)
vendor/bin/tester -c tests/php-coverage.ini --coverage-src src/ --coverage ~/report.html tests/  

# remove test artifacts
rm -rf tests/temp/cache/

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.