Code Monkey home page Code Monkey logo

laravel-langman's Introduction

Laravel Langman

Langman is a language files manager in your artisan console, it helps you search, update, add, and remove translation lines with ease. Taking care of a multilingual interface is not a headache anymore.

Laravel Langman
Build Status StyleCI Latest Stable Version Total Downloads License

Installation

Begin by installing the package through Composer. Run the following command in your terminal:

$ composer require themsaid/laravel-langman

Once done, add the following line in your providers array of config/app.php:

Themsaid\Langman\LangmanServiceProvider::class

This package has a single configuration option that points to the resources/lang directory, if only you need to change the path then publish the config file:

php artisan vendor:publish --provider="Themsaid\Langman\LangmanServiceProvider"

Usage

Showing lines of a translation file

php artisan langman:show users

You get:

+---------+---------------+-------------+
| key     | en            | nl          |
+---------+---------------+-------------+
| name    | name          | naam        |
| job     | job           | baan        |
+---------+---------------+-------------+

php artisan langman:show users.name

Brings only the translation of the name key in all languages.


php artisan langman:show users.name.first

Brings the translation of a nested key.


php artisan langman:show package::users.name

Brings the translation of a vendor package language file.


php artisan langman:show users --lang=en,it

Brings the translation of only the "en" and "it" languages.


php artisan langman:show users.nam -c

Brings only the translation lines with keys matching the given key via close match, so searching for nam brings values for keys like (name, username, branch_name_required, etc...).

In the table returned by this command, if a translation is missing it'll be marked in red.

Finding a translation line

php artisan langman:find 'log in first'

You get a table of language lines where any of the values matches the given phrase by close match.

Searching view files for missing translations

php artisan langman:sync

This command will look into all files in resources/views and app and find all translation keys that are not covered in your translation files, after that it appends those keys to the files with a value equal to an empty string.

Filling missing translations

php artisan langman:missing

It'll collect all the keys that are missing in any of the languages or has values equals to an empty string, prompt asking you to give a translation for each, and finally save the given values to the files.

Translating a key

php artisan langman:trans users.name
php artisan langman:trans users.name.first
php artisan langman:trans users.name --lang=en
php artisan langman:trans package::users.name

Using this command you may set a language key (plain or nested) for a given group, you may also specify which language you wish to set leaving the other languages as is.

This command will add a new key if not existing, and updates the key if it is already there.

Removing a key

php artisan langman:remove users.name
php artisan langman:remove package::users.name

It'll remove that key from all language files.

Renaming a key

php artisan langman:rename users.name full_name

This will rename users.name to be users.full_name, the console will output a list of files where the key used to exist.

Notes

langman:sync, langman:missing, langman:trans, and langman:remove will update your language files by writing them completely, meaning that any comments or special styling will be removed, so I recommend you backup your files.

Web interface

If you want a web interface to manage your language files instead, I recommend Laravel 5 Translation Manager by Barry vd. Heuvel.

laravel-langman's People

Contributors

ahmedash95 avatar fergthh avatar joelcuevas avatar lex111 avatar m1guelpf avatar mbardelmeijer avatar omranic avatar phainv avatar stygiansabyss avatar themsaid avatar vinkla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-langman's Issues

Improvements

Hi. It's just an idea but I think it could be useful.

-i think the show command can be improved.

One improvement consists in adding an optional param language.

php artisan langman:show auth en / php artisan langman:show auth.failed en to show the auth translations for one language. If the language passed does not exists, the show the languages available (maybe another command to show the available languages? )

Another improvement is about how the translations are displayed when you have several languages and/or long strings.
Transposing the data? Display two languages at a time and repeat the header? Setting based ?

With five languages which is not so uncommon in european apps (en, fr, de, es, pt) it becomes a mess on the screen.

messy

Keep up the good work.

Bugs in windows environment

Hi

Don't know if it happens on other platforms but it happens on windows.
Verified on a fresh laravel install.

show01

So far, so good.

The issue comes up when I try to add a new translation

error01

The problem is in Manager.php - fillKeys($fileName, array $keys)method.

$filePath = $this->path."/{$languageKey}/{$fileName}.php"; : first translation results in C:\Work\www\projects\dummy\resources\lang/C:\Work\www\projects\dummy\resources\lang\en/auth.php

The workaround was $filePath = "{$languageKey}/{$fileName}.php"; . The result is C:\Work\www\projects\dummy\resources\lang\en/auth.php and new translations were added with success.

success

The sync command has issues too:

error02

Then added another translation mannualy and tried the missing command

error03

There's a success message but the translation was not added to es/auth.php

The remove command fails too.

error04

Cheers

Show translation in default language

I have a very large translation database and translating it now is quite difficult even with this awesome package. It would be nice if the text that I need to translate is shown in the already available translation, for example the default language of the app (app.locale config).

So if I have my app with default language in English, than I would like to translate it to some other language. But I need to see what the actual text is I need to translate in the default app language, because the key is not self explanatory enough.

It would be really nice if this would be an option.

php artisan langman:trans vendor error

How to create the issue:

  1. Create a vendor directory in lang
php artisan langman:trans nav.new_item
> Create item

Error:

Undefined index: vendor

Laravel Version: 5.2

php artisan langman:show validation - Error strstr() expects parameter 1 to be string, array given

Hi

Found this error while working in a 5.2.31 app and tested in a fresh 5.2.32.

The error only occurs when showing validation. It works ok with auth, passwords, pagination language files.

ok-1

err-1

[2016-05-17 14:20:43] local.ERROR: ErrorException: strstr() expects parameter 1 to be string, array given in C:\Work\www\projects\aa\vendor\symfony\console\Helper\Table.php:398
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'strstr() expect...', 'C:\\Work\\www\\pro...', 398, Array)
#1 C:\Work\www\projects\aa\vendor\symfony\console\Helper\Table.php(398): strstr(Array, '\n')
#2 C:\Work\www\projects\aa\vendor\symfony\console\Helper\Table.php(256): Symfony\Component\Console\Helper\Table->buildTableRows(Array)
#3 C:\Work\www\projects\aa\vendor\laravel\framework\src\Illuminate\Console\Command.php(339): Symfony\Component\Console\Helper\Table->render()
#4 C:\Work\www\projects\aa\vendor\themsaid\laravel-langman\src\Commands\ShowCommand.php(95): Illuminate\Console\Command->table(Array, Array)
#5 [internal function]: Themsaid\Langman\Commands\ShowCommand->handle()
#6 C:\Work\www\projects\aa\vendor\laravel\framework\src\Illuminate\Container\Container.php(507): call_user_func_array(Array, Array)
#7 C:\Work\www\projects\aa\vendor\laravel\framework\src\Illuminate\Console\Command.php(169): Illuminate\Container\Container->call(Array)
#8 C:\Work\www\projects\aa\vendor\symfony\console\Command\Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 C:\Work\www\projects\aa\vendor\laravel\framework\src\Illuminate\Console\Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 C:\Work\www\projects\aa\vendor\symfony\console\Application.php(791): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 C:\Work\www\projects\aa\vendor\symfony\console\Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(Themsaid\Langman\Commands\ShowCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 C:\Work\www\projects\aa\vendor\symfony\console\Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 C:\Work\www\projects\aa\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 C:\Work\www\projects\aa\artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 {main}  

Cheers

Double quotes get slash

Steps to reproduce:

  1. Create new label and enter text Hello "zorro":
    php artisan langman:trans labels.bye
  2. Now check the lang file and see that the double quotes have slashes, this is the output:
    `
'Hello \"zorro\"' ); ` Seems it's the addslashes in the Manager that causes this, possibly try to use var_export instead of stringLineMaker() function? This is what the Manager.php's writeFile function could look like: ` ``` public function writeFile($filePath, array $translations) { $content = "

Lang files in sub-directories of the app not handled (non-vendor)

  • Laravel Version: 5.8.0
  • PHP Version: 7.2.0
  • Database Driver & Version: mysql

Description:

Language files under sub-directories are not taken into consideration.

e.g.:

/en
   /menu
       menu.php

The above is valid and can be accessed using __('menu/nav.some-key').

However, this package doesn't recognise them.

Steps to reproduce:

Add a language file in the file structure above (with some keys).

Then run php artisan langman:show menu/nav

Excepted Result
See the keys and their translations

Actual Result
No keys are shown

key with '.' in it, creates nested key

Laravel Version: 5.7.9
PHP Version: 7.1.19
Database Driver & Version: MySQL 5.7.23

Description:

When you have a key in a language-file with a . (e.a. 'No.' in it and run php artisan langman:sync and a language is missing that key, it doesn't add the key the same way but changes it to:

    'No' => [
        '' => '',
    ],

instead of

    'No.' => '',

Steps to reproduce:

See description

Supporting modules/ folder

  • Laravel Version: 5.3.6
  • PHP Version: 7.0.8
  • Database Driver & Version: MySQL 5.6

Description:

How will one use the sync command to scan the modules/ folder as well. we have several modules and we would like to sync the translations from the views under modules/Admin/Resources/views

We extended the provider and changed the paths but it wont recognize the 'trans' calls in the views.

Thanks.

Lang files are not PSR-2

  • Laravel Version: 5.1
  • PHP Version: 5.6
  • Database Driver & Version:

Description:

Whenever I add translations in lang files via langman, Langman does not write into files according to PSR-2 standards.
1- It adds one space after "<?php "
2- It does not add line break at the end of array

Steps to reproduce:

1- add any translation via langman

Create lang file dynamically

  • Laravel Version: 5.6
  • PHP Version: 7.2
  • Database Driver & Version:

Description:

Hi,

I would like to create a lang file(or if exists) and add a new key with translated text in one just command.
for example :
php artisan langman:trans users.name --lang=en --text="this a translation"
is that possible?

Regards

Steps to reproduce:

Ignore files

  • Laravel Version: 5.7.9
  • PHP Version: 7.1.9
  • Database Driver & Version: MySQL 5.7.23

Description:

I want to have the possibility to ignore the default language-files (auth.php, pagination.php, passwords.php, validation.php)

New keys created by langman should be in default language rather than empty

Langman creates new files with new keys which are empty.

Problem is that translators who receive those files will have to look into the original language files to know what the original message is before they can translate it.

It would be useful to have a default language instead of an empty string.

Utf8 Character Translation Not Working

  • Laravel Version: 5.7.2
  • PHP Version: 7.2.4
  • Database Driver & Version: MariaDB 10.1.31

Description:

langman:trans command is not translating UTF8 characters (like ş, ğ, ı)

Steps to reproduce:

php artisan langman:trans messages.title
Başlık
messages.title:tr was set to "Ba\l\k" successfully.

Specify language for missing

Description:

add --lang option to php artisan langman:missing so you can specify which language you want to check. Right now the command checks all language files and if you only want to check the English one, you first got to skip all other inputs for other languages

Empty array on lang file throws offset error when syncing

  • Laravel Version: 5.7.12
  • PHP Version: 7.2.9

Description:

By far not an urgent issue, just thought I should report that running php artisan langman:sync throws ErrorException : Undefined offset: 2 when "Synchronizing language files..." if you have any php lang file that only returns an empty array.

Steps to reproduce:

  • Create a .php file in any of your lang folders;
  • Edit it so it returns just an empty array:
<?php

return [
    //
];
  • Run php artisan langman:sync

Sync not matching some methods

Sync is ignoring @lang and @choice if they are used just after an HTML tag.
For example: <p>@lang('language.line')</p>
The problem is that the regex is ignoring them because the first part: [^\w|>]
Is that the expected behavior?
I have been playing with the regex in https://regex101.com/r/jS5fX0/2 but I'm not sure how to solve this in the right way.

langman:sync autocreate

  • Laravel Version: 5.4
  • PHP Version: 7.1
  • Database Driver & Version: Mysql 5.7.19

Description:

Hi.
I think that it'd be very usefull to auto create files of scanned $allkeysInFiles.
maybe here SyncCommand@syncKeysFromFiles or in other function..
because there are a lot of results found but no new translation file is created!
if you can add it please!

Steps to reproduce:

all tests is broken

i'm trying to solve the problem but i think you could do it faster than me , could you please check all tests

@themsaid

Support for nested keys

opening another issue to request support for nested keys (as mentioned in #3, but to keep feature requests separated).

Keys re-created each sync?

When I run twice the command to sync files, I get lots of message on first run which say "message XXX has been added" but I also get those same messages each time I run the command.

When I run the command twice I would only expect an update to my files only the first time, and the second run should see nothing to sync (no message added).

Right?

Command to synchronize languages (not from views, just between languages)

Say we have for instance the following language files and keys:

lang/en/users.php   [ 'name' => 'Name' ]
lang/en/address.php [ 'city' => 'City', 'zip' => 'Zip code' ]

lang/fr/users.php   [ 'name' => 'Nom' ]
lang/fr/address.php [ 'city' => 'Ville' ]

lang/de/users.php   [ 'name' => 'Name' ]

We need a command which would synchronize all languages with the same keys.

A translator will not have access to php artisan, so the command missing will not really help in this case.

That command in that example would:

  • create the file lang/de/address.php with all keys,
  • add the key zip to the file lang/fr/address.php

Of course, that command needs to know which language is our reference (in this example, en is the reference language), that could be a setting in config for instance and/or could be overridden in the command line.

question

so is this for translation for a single language non-english app, or an app with multiple language selection?

In readme langman:translate command

php artisan langman:translate users.name
php artisan langman:translate users.name.en

i get no command "translate" it's "trans"

php artisan langman:trans users.name
php artisan langman:trans users.name.en

Ignore "arrays" when sync

Hi,

I have this lang file e.g

// file lang/users.php
return [
   'tips' => [
      'one' => 'First tip',
      'two' => 'Second tip',
      // etc.
   ]
];

And in a controller or a file inside app directory:

// lang('users.tips') is an array
foreach (lang('users.tips') as $tip) {
   // do something with the texts
}

So the problem is that when I use "langman:sync" command, it writes an empty array in tips.

// file lang/users.php
return [
   'tips' => ''
];

Is this a bug or an expected behauvior?

Anyway, congrats for the package, it rocks.

[IDEA] Vue i18n integration

Could be a useful idea an integration with this package https://github.com/kazupon/vue-i18n

I'am using and generate a JS object with https://github.com/martinlindhe/laravel-vue-i18n-generator, but the call of key for translate is some like this $t('message.hello') and the the workflow for include the key is manual, not like the easy command php artisan langman:sync.

Example in Vue template file:

<div class="message">
    <p>{{ $t('message.hello', {name: 'visitor'}) }}</p>
</div>

It's just an idea, if you need more details let me know ;)

test

  • a task list item
  • list syntax required
  • normal formatting, @mentions, #1234 refs
  • incomplete

Undefined offset: 1

$ php artisan langman:missing
Looking for missing translations...

  [ErrorException]
  Undefined offset: 1

No idea why that happens. I got some vendor files and maybe some files are created in one language and not in the others.

Purge unused strings

How about a command for purging unused strings in lang files?

There is a potential problem with trans('app.type_' . $type) kind of translations, as the user will create custom entries in the files... but, still, I think that a command like this would be useful.

Maybe all the custom strings could be placed in files that could be blacklisted from purging at config level.

@themsaid, have you thought about a feature like this?

Arabic (ar) support

  • Laravel Version: 5.8
  • PHP Version: 7.2
  • Database Driver & Version:

Description:

I noticed that when I use langman artisan command to make an Arabic translation it aborts without adding the translation and without carrying-on to the other languages.

As an overall observation, Arabic is not supported every command (sync, missing, trans...) throws errors when Arabic is around.

Steps to reproduce:

add an Arabic translation to to resources/lang/ar folder and use langman.

image

0 => 1 array key value

  • Laravel Version: 5.3.6
  • PHP Version: 7.0.8
  • Database Driver & Version: MySQL 5.6

Description:

When running sync i get the following

<?php 

return [
    '0' => '1',
    'access' => [
        'test' => '',
    ],
];

the 0 => 1 is always there i am not sure how that's added.

Steps to reproduce:

Disable URL on production

Is that possible disable mysite.com/langman url on production environment?

I think its a security issue.

ErrorException When Calling the Manager files() Function In Laravel 5.1

When I inject the Manager into a command I'm writing in our Laravel 5.1 based app so I can utilize its methods I am able to successfully do this:
$allViewsKeys = $this->manager->collectFromFiles();

But when I try and do this:
$translationFiles = $this->manager->files();

I get the error:
[ErrorException]
Missing argument 2 for Themsaid\Langman\Manager::Themsaid\Langman{closure}()

But is seems all our system variables are in the places the module is expecting the find them.

Scan Error - Cannot read property 'Login' of undefined

  • Laravel Version: 5.7
  • PHP Version: 7.2.1

Description:

When I click Scan, I got this error in the console:
langman.js:42763 Uncaught TypeError: Cannot read property 'Login' of undefined
at Vue$3.addNewKey (langman.js:42763)
at Vue$3.boundFn [as addNewKey] (langman.js:33189)
at _.forEach.key (langman.js:42835)
at arrayEach (langman.js:14459)
at Function.forEach (langman.js:23281)
at Object.$.post.done.response (langman.js:42834)
at fire (langman.js:6979)
at Object.fireWith [as resolveWith] (langman.js:7109)
at done (langman.js:12934)
at XMLHttpRequest. (langman.js:13176)

Steps to reproduce:

Just click the 'Scan' button

php artisan langman:trans addslashes error

How to create the issue:

php artisan langman:trans nav.new_item
> Create new item

Error:

addslashes() expects parameter 1 to be string, array given

Laravel Version: 5.2

Sub-directories translations

3rd party packages sometimes allow to publish translation files.

Those file are usually located inside a subfolder of lang. For instance:

lang
  |_ en
  |_ fr
  |_ es
  |_ vendor
    |_ package1
    | |_ en
    | |_ fr
    | |_ es
    |_ package2
      |_ en
      |_ es
  • Is that supported by your tool?
  • Will package1/package2 get updated too?
  • Will fr be created in package2 folder?

Sync is ignoring anything outside views

There are lots of places where we have messages: controllers, validation, events, etc. All of them are not taken into account, just the views.

This would be fair to incorporate those classes into the sync process.

Lower PHP requirement

You currently require PHP7, which is way above the requirement set by Laravel itself. Could you update the composer file so that we can still install it?

key with ' in it, breaks it

  • Laravel Version: 5.7.9
  • PHP Version: 7.1.19
  • Database Driver & Version: MySQL 5.7.23

Description:

When you have a key in a language-file with a \' in it and run php artisan langman:missing it works okay and you can translate things, but when you run php artisan langman:missing again, it crashes because langman overwrites the key with \' and changes it to '

Steps to reproduce:

  1. Add a key to a language-file with \' in it. e.a. 'today's posts'
  2. Run php artisan langman:missing (also works with php artisan langman:trans KEY) (note: you also cannot use the 'today's posts' as key)
  3. Translate (or press Enter)
  4. Run php artisan langman:missing again -> crash and 'today's posts' is changed to 'today's posts'

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.