Giter Site home page Giter Site logo

blair2004 / laravel-translatable-string-exporter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kkomelin/laravel-translatable-string-exporter

0.0 2.0 0.0 81 KB

Translatable String Exporter for Laravel >= 5.4

License: MIT License

PHP 100.00%

laravel-translatable-string-exporter's Introduction

Translatable String Exporter for Laravel >= 5.4

Build Status

As we know, Laravel 5.4 has introduced a "new" way of string translation. Now you can use __('Translate me') or @lang('Translate me') with translations in JSON files to translate strings. Translatable String Exporter is aimed to collect all translatable strings of an application and create corresponding translation files in JSON format to simplify the process of translation.

Installation

  1. Add kkomelin/laravel-translatable-string-exporter to your project:
composer require kkomelin/laravel-translatable-string-exporter
  1. For Laravel >= 5.5 we use Package Auto-Discovery, so you may skip this step. For Laravel < 5.5, add ExporterServiceProvider to the providers array in config/app.php:
KKomelin\TranslatableStringExporter\Providers\ExporterServiceProvider::class,

Configuration

To change project defaults, use the following command to create a configuration file in your config folder and make necessary changes in there:

php artisan vendor:publish --provider="KKomelin\TranslatableStringExporter\Providers\ExporterServiceProvider"

Usage

Export translatable strings

php artisan translatable:export <lang>

Where <lang> is a language code or a comma-separated list of language codes.
For example:

php artisan translatable:export es
php artisan translatable:export es,bg,de

The command with the "es,bg,de" parameter passed will create es.json, bg.json, de.json files with translatable strings or update the existing files in the resources/lang folder of your project.

Find untranslated strings in a language file (command)

To inspect an existing language file (find untranslated strings), use this command:

php artisan translatable:inspect-translations fr

Only one language at a time, please.

To export translatable strings for a language and then inspect translations in it, use the following command:

php artisan translatable:inspect-translations fr --export-first

Find untranslated strings in a language file (IDE)

An alternative way to find untranslated strings in your language files is to search for entries with the same string for original and translated. You can do this in most editors using a regular expression.

In PhpStorm, you can use this pattern: "([^"]*)": "\1"

Persistent strings

Some strings are not included in the export, because they are being dynamically generated. For example:

{{ __(sprintf('Dear customer, your order has been %s', $orderStatus)) }}

Where $orderStatus can be 'approved', 'paid', 'cancelled' and so on.

In this case, you can add the strings to the <lang>.json file manually. For example:

  "Dear customer, your order has been approved": "Dear customer, your order has been approved",
  "Dear customer, your order has been paid": "Dear customer, your order has been paid",
  ...

In order for those, manually added, strings not to get removed the next time you run the export command, you should add them to a json file named persistent-strings.json. For example:

[
  "Dear customer, your order has been approved",
  "Dear customer, your order has been paid",
  ...
]

License & Copyright

MIT, (c) 2018 Konstantin Komelin

laravel-translatable-string-exporter's People

Contributors

kkomelin avatar t1sh0o avatar kohlerdominik avatar mabdelrahman91 avatar efriandika avatar tommyschmiedel avatar

Watchers

James Cloos 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.