translation / laravel Goto Github PK
View Code? Open in Web Editor NEWLaravel translation made __('simple').
Home Page: https://translation.io/laravel
License: MIT License
Laravel translation made __('simple').
Home Page: https://translation.io/laravel
License: MIT License
UPDATE: Also add an error if source language is present in target languages. We don't accept that and the backend triggers an error.
We've encountered an issue where having a blade component with a translated string as a attribute. Example code below:
<x-form-row :label="t('Name')"></x-form-row>
This unfortunately won't get picked up when running the sync command. There are ways around this obviously but I just wondered if anyone has an idea on if this could be solved?
I've tried to initiate a new project, based on Laravel 11. The init
command runs without error, but the project site isn't showing translations.
With a translation:sync
I got:
php artisan translation:sync
Sync started
ErrorException
file_put_contents(C:\laragon\www\secpal\lang\.translation_io): Failed to open stream: No such file or directory
at vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php:204
200▕ * @return int|bool
201▕ */
202▕ public function put($path, $contents, $lock = false)
203▕ {
➜ 204▕ return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
205▕ }
206▕
207▕ /**
208▕ * Write the contents of a file, replacing it atomically if it already exists.
1 vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php:204
2 vendor\tio\laravel\src\Service\SourceEditSync.php:166
Illuminate\Filesystem\Filesystem::put("C:\laragon\www\secpal\lang\.translation_io", "{"timestamp":1715527102}")
The reason is, that Laravel 11 doesn't create an lang
directory by default, anymore. I'm using __('My Text')
, so I created/published it neither.
A php artisan lang:publish
and another php artisan translation:init
fixed it.
So I think, the problem isn't the Windows environment but the missing/not published lang folder.
In reading the Laravel 9 upgrade, they are moving the lang directory from resources/lang to the project directory.
Are you going to implement this change?
Is it possible to get support for Laravel 8?
Hello,
This isn't a bug report but simply a question. We've been using this package for a while now and everything works well. However I need to add a couple of hundred new translations (that I already have as .php files). However, when I run the sync command, I only get the source texts imported. All my translation files are overwritten with empty data from translation.io.
I guess this is the way it's intended since it seems to use translation.io as a "source of truth".
But still, I don't really have the time to add all these manually. Is there a way to sort of "re-init" or sync with the codebase as the source? Or is the only solution to create a new project from scratch?
Hi.
How systems can scan resources/lang/vendor folder too to translated ?
We have a very large application that has multiple JSON translation files, registered with Lang::addJsonPath()
. These files are split based on multiple modules within the app.
It looks like it'd be relatively simple to update GettextPOGenerator::jsonFiles()
to use all the registered JSON paths. Something like:
$paths = [$this->application['path.lang']];
$loader = Lang::getLoader();
if ($loader instanceof FileLoader) {
foreach ($loader->jsonPaths() as $jsonPath) {
$paths[] = $jsonPath;
}
}
foreach ($paths as $path) {
foreach (glob($path . DIRECTORY_SEPARATOR . '*.json') as $filename) {
$files[] = $filename;
}
}
The trickier issue would be resolving which JSON file to write back to on sync. Is this something you're interested in supporting? I've been digging around in GettextTranslationSaver
and it seems like it'd take a bit of a refactor to support this use-case.
With a vanilla Laravel 8.10.0 project, I am getting the following error when calling translation:init
Init started
Exception
Folder "app" doest not exists. Gettext scan aborted.
at /var/www/project/vendor/tio/laravel/src/GettextPOGenerator.php:52
48▕
49▕ // Extract GetText strings from project
50▕ foreach ($directories as $dir) {
51▕ if (!is_dir($dir)) {
➜ 52▕ throw new \Exception('Folder "' . $dir . '" doest not exists. Gettext scan aborted.');
53▕ }
54▕
55▕ foreach ($this->scanDir($dir) as $file) {
56▕ if (strstr($file, '.blade.php')) {
+18 vendor frames
19 /var/www/project/artisan:37
Illuminate\Foundation\Console\Kernel::handle()
The config which directories to scan is unchanged with 'gettext_parse_paths' => ['app', 'resources'],
Hi there,
I want you to notice, that on PHP 8.2 I've got a warning:
Creation of dynamic property Tio\Laravel\GettextTranslationSaver::$config is deprecated in <...>/vendor/tio/laravel/src/GettextTranslationSaver.php on line 26
PHP: 8.2.4
Laravel: 9.52.5
Hi, it would be great if you can release a new version with Laravel 6 support.
After I init the translation (seemingly successfully, see output below), the backend still shows the "setup" page. If i try to php artisan translation:sync
it tells me: {"error":"This project has not been initialized yet. Please use the \"init\" operation."}
wven though I already initialized.
My translation.php
<?php
return [
'key' => env('TRANSLATIONIO_KEY'),
'source_locale' => 'de-CH',
'target_locales' => ['fr-FR'],
/* Directories to scan for Gettext strings */
'gettext_parse_paths' => ['app', 'resources'],
/* Where the Gettext translations are stored */
'gettext_locales_path' => 'resources/lang/gettext'
];
The key is in my .env
How i start the initialization: $ docker-compose exec app php artisan translation:init
The output I get
Init started
Init ended with success
----------
Use this URL to translate: https://translation.io/sandrotanner/my-project-name
----------
Do your logs give any insight on what might go wrong? Thanks in advance :)
BTW I use Laravel 8 and the official php docker image "php:8.0-fpm"
Hello,
I'm wondering if there is a way to register translation keys that come from other sources rather than being hardcoded.
Example use case is having a set of data (e.g. API or local constants), which need to be translated, but they would need to be changed over time.
I would envision a need for a separate scanning tool, that would require a script to be fully functional and therefore would be able to read variables/constants runtime.
Use example:
class User {
const ROLE_ADMIN = 'admin';
}
//dynamic-translations.php
rtp('enums.user-roles', User::ROLE_ADMIN);
//config/translation.php
'scan_runtime' => [
'runnable-file.php'
];
//Result:
msgctxt "enums.user-roles"
msgid "admin"
msgstr ""
If one wants to change the value of ROLE_ADMIN
to let's say, administrator, it would need to be done in just one place.
In theory, is this something that you would be eager to have as a part of your package?
i got error php 8
Gettext\Utils\FunctionsScanner::Gettext\Utils{closure}(): Argument #1 ($carry) must be passed by reference, value given
Hi!
I am using the v1.12 of your package, and PHP 7.3.23.
I have a translation.php file as follows:
...
'source_locale' => 'de',
'target_locales' => ['en'],
/*
|--------------------------------------------------------------------------
| # Ignored PHP key prefixes.
|--------------------------------------------------------------------------
|
| Ex: * 'validation': ignore the whole validation.php file.
| * 'validation.custom': ignore the "custom" subtree in validation.php file.
| * 'subfolder/more': ignore the whole subfolder/more.php file.
|
*/
'ignored_key_prefixes' => ['legacy', 'validation'],
...
So, I want to translate from german to english.
The validation.php
file is only available in the en
, but not in the de
folder (as I just need this file for internalt tests). So I have some structure like this:
de/
file1.php
file2.php
en/
file1.php
validation.php
But although validation
is mentioned in the ignored_key_prefixes
, the en/validation.php
file is removed after I call php artisan translation:sync
. My structure after syncing is:
de/
file1.php
file2.php
en/
file1.php
file2.php
If I understand correctly, the file en/validation.php
should not be touched, because it is ignored, so I think I found a bug here?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.