• Stars
    star
    301
  • Rank 138,011 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 7 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Translatable String Exporter for Laravel

Translatable String Exporter for Laravel

Tests Status Badge PHPStan Status Badge Code Styles Check Badge

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.

Versions

Package PHP
<=1.15.1 5.6
>1.15.1 ^7.2|^8.0
>1.18.0 ^8.0

Even though we drop support for PHP versions in minor releases, Composer ensures that users with previous versions of PHP don't get not-yet-supported PHP code.

Installation

Normally, it's enough to install the package as a development dependency.

composer require kkomelin/laravel-translatable-string-exporter --dev

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 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

The command only supports inspecting one language at a time.

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 and VSCode, 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) 2017-present Konstantin Komelin and contributors

More Repositories

1

isomorphic-dompurify

Use DOMPurify on server and client in the same way
JavaScript
387
star
2

insecres

A console tool that finds insecure resources on HTTPS sites
Go
40
star
3

sui-dapp-starter

Full-Stack Sui Starter on Steroids
TypeScript
23
star
4

react-select-customization-examples

React Select Customization Examples
TypeScript
9
star
5

susyboot

Susy-powered Bootstrap grid replacement
CSS
8
star
6

create-fhenix-dapp

"Create React App" for Fhenix DApps
TypeScript
6
star
7

designless

Bootstrap 3 powered Drupal 7 theme with minimalistic design intended for personal blogs and other content centered sites.
CSS
5
star
8

sui-explorer-local

Local Sui Explorer: Cli
JavaScript
5
star
9

grunt-kickstart

Basic configuration for Grunt with SASS, Compass and LiveReload
JavaScript
4
star
10

yashare_counters_update

Yandex.Share with Counters Update (Drupal 7 module)
PHP
3
star
11

tailwindcss-counter

Tailwind CSS plugin to generate counter utilities
JavaScript
3
star
12

ashtangamoon-solid

Progressive Web App (PWA) for keeping track of full and new moon days
TypeScript
3
star
13

drupal_bulk_upgrade

Shell script for bulk upgrade of Drupal sites
Shell
2
star
14

idna_convert

The project moved from Drupal.org because of their license policies. The code is under GPL, but it includes a LGPL library.
2
star
15

marrysign

MarrySign (Backend/Blockchain)
TypeScript
2
star
16

create-sui-dapp

Sui dApp Starter: Cli
TypeScript
2
star
17

vue_drupal_demo

Drupal 8 module that implements demo functionality for Vue.js presentation given at DrupalCamp Krasnodar 2016
PHP
2
star
18

picback

A simple Angular app that consumes Drupal 8 RESTful WebServices. It allows to leave feedback in the format of pictures.
JavaScript
2
star
19

qrcoder

Drupal 8 module that provides QR Code field formatter for the core Link field.
PHP
2
star
20

ashtangamoon-vanilla

Progressive Web App (PWA) for keeping track of full and new moon days
JavaScript
2
star
21

rwdemo_drupal

Demo Drupal theme for the "Responsive Web Design & Drupal" presentation at Drupal White Nights 2014.
PHP
1
star
22

sui-dapp-kit-theme-creator

Turns colors into Sui dApp Kit themes
TypeScript
1
star
23

icearrow-extension

Chrome Extension for IceArrow
JavaScript
1
star
24

catchsmile

Catch a Smile Drupal 7 module
JavaScript
1
star
25

kafka-experiment-1

A Kafka experiment
JavaScript
1
star
26

RWDemo

Responsive Web Design demonstration for my presentation at Evercode Talks 3
1
star
27

nextjs-image-optimization-examples

Code examples for the Next.js image optimization tutorial https://uploadcare.com/blog/next-js-image-optimization/
JavaScript
1
star
28

catchsmile-wp7

Catch a Smile Windows Phone 7 application
C#
1
star
29

sui-dapp-starter.dev

Sui dApp Starter SIte
TypeScript
1
star