g4/translate

g4 i18n php library

1.0.0 2024-03-01 09:16 UTC

This package is auto-updated.

Last update: 2024-10-30 10:44:27 UTC


README

  • Configuration of the gettext extension
  • Utlity tool to generate .mo files
  • Utility tool for extracting template strings

Install

Using Composer and Packagist

composer require g4/translate

Resources

Requirements

Usage

Set locale early in the program before rendering any internationalized template.

use G4\Translate\Locale\Locale;
use G4\Translate\Locale\Options;

$options = new Options();
$options
    ->setDomain('myDomain')
    ->setLocale('en_US')
    ->setPath('/path/to/locale/files');
(new Locale($options))->set();

Command line interface

Convert .po files to .mo

./vendor/bin/translate --path /path/to/locale/files

where --path is path to your locale folder

Extract template strings

./vendor/bin/translate-extract -t /path/to/templates -w /path/to/tmp -g /path/to/locale/files -d myDomain

where:

  • -t is path to folder that contains templates
  • -w is path to temp folder
  • -g is path to folder where myDomain.po file with strings will be generated
  • -d domain name

Development

Install dependencies

$ make install

Run tests

$ make test

License

(The MIT License) see LICENSE file for details...