Comments (9)
Of course, Yurii. Thanks
from laravel-translatable-string-exporter.
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.
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.
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.
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.
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
from laravel-translatable-string-exporter.
functions don't work the same
Ah Okay. Good to know. Thanks.
from laravel-translatable-string-exporter.
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.
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)
- Strings with quotes get truncated or escaped again HOT 3
- Strings containing round brackets are truncated improperly HOT 1
- Make it possible to exclude some folders from the search HOT 12
- It cannot handle `__('Search...')`
- Exclude short translation keys from export HOT 6
- JSON File HOT 1
- Parsing Issues still persist HOT 5
- Ability to add comments that provide enhanced features HOT 3
- Undetected strings if "key"-argument starts on new line HOT 4
- Does not support new Laravel 9 directory structure HOT 12
- Drop support for PHP 5.6 in 1.16.0 HOT 4
- Release 1.16.0 HOT 2
- require-dev instead of require ? HOT 5
- Split short-keyed translations into separate directories/files? HOT 1
- Drop support for PHP 7.4 and Laravel 5.x/6.x/7.x
- Enable `exclude-translation-keys` by default
- [feature-request] per function transformation HOT 5
- Changing export directory HOT 1
- excluded-directories does not work as expected HOT 3
- Not adding new string on inspect-translations HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-translatable-string-exporter.