Giter VIP home page Giter VIP logo

Comments (9)

kkomelin avatar kkomelin commented on May 31, 2024 1

Of course, Yurii. Thanks

from laravel-translatable-string-exporter.

kkomelin avatar kkomelin commented on May 31, 2024

Thanks for your question @yurii-github.
It's easy. Just wrap each text string from resources/lang/{lang}/{key}.php into __() function and run export again.

from laravel-translatable-string-exporter.

yurii-github avatar yurii-github commented on May 31, 2024

evening

yes, I understood that I could use such approach, and I did it for some strings, but in result those strings will be saved in en.json file as

[
  "validation.some.error": "error msg"
 ]

but not in en/validation.php as I want

[
 "some.error" => "error msg"
]

So, my point is, to use trans() to store in php file, and use __() to store in json file. Or do you think it makes no sense to separate ton of validation strings into its own space?

regards

from laravel-translatable-string-exporter.

yurii-github avatar yurii-github commented on May 31, 2024

I'll check tomorrow with file persistent-strings.json , so all custom overrides for laravel validation strings won't be deleted. maybe putting all strings into single json file is not such a bad idea..

from laravel-translatable-string-exporter.

kkomelin avatar kkomelin commented on May 31, 2024

yes, I understood that I could use such approach, and I did it for some strings, but in result those strings will be saved in en.json file as

[
  "validation.some.error": "error msg"
 ]

No, they won't.

First of all, if English is your default language, you don't need that en.json.
Secondly, if you only wrap text strings (not keys) into __(), the format of the translation file will be:

{
"error msg": "error msg"
}

If the format of your JSON translation file is not like this, it may be a bug. Please give me more details on the issue. What do you wrap into __() and what result do your receive after export?

So, my point is, to use trans() to store in php file, and use __() to store in json file.

As I know, in Laravel trans() and __() works the same, so I don't see much sense in adding extra meaning to one of them.

from laravel-translatable-string-exporter.

yurii-github avatar yurii-github commented on May 31, 2024

in my app default language can be changed from en to anything else. I just use english strings so I can understand what is all about. in some places i use keys instead, like in validation strings, so errors can be structured, so i use trans() for keyed strings and __() for readable strings

functions don't work the same

// read from structured translation strings, and fallback to json if no found
trans() --> return app('translator')->trans($key, $replace, $locale)->get($key, $replace, $locale)->parseKey($key) 

// read from json file, and fallback to structured if not found
__() --> return app('translator')->getFromJson($key, $replace, $locale);  

something like that

image

from laravel-translatable-string-exporter.

kkomelin avatar kkomelin commented on May 31, 2024

functions don't work the same

Ah Okay. Good to know. Thanks.

from laravel-translatable-string-exporter.

yurii-github avatar yurii-github commented on May 31, 2024

if you don't mind i will hold this issue open for a while. i may add my solution when have some time or maybe somebody will come up with their own.

regards

from laravel-translatable-string-exporter.

kkomelin avatar kkomelin commented on May 31, 2024

Just added the 'exclude-translation-keys' option to the config file https://github.com/kkomelin/laravel-translatable-string-exporter/blob/master/config/laravel-translatable-string-exporter.php#L40 which allows to ignore/exclude short translation keys from JSON export, so you may try to use both translation approaches together.

from laravel-translatable-string-exporter.

Related Issues (20)

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.