Typically, the actual translating process is performed by external non-dev people, right?
But the developer's role here is to prepare all the structure well and to give clear instructions to the translator. In this and a few upcoming lessons, let's discuss how can we perform our part of the process.
In our application we'll most likely have 1 JSON file per language:
lang/en.json
{ "Dashboard": "Dashboard", "Log in": "Log in", "Register": "Register", "You're logged in!": "You're logged in!", // ...}
So, you send this file to the translator, with these instructions:
:
to the target language.:
is not changed.I like this approach for site-wide translations, because it's easy to understand, and it's easy to translate. You instantly see the whole context of the translation.
Our application currently has these files (we've ignored default files):
lang/en/auth.php
return [ 'failed' => 'These credentials do not match our records.', 'password' => 'The provided password is incorrect.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 'register' => 'Registration', // ...];
lang/en/general.php
return [ 'dashboard' => 'Dashboard', 'youAreLoggedIn' => 'You are logged in!', 'cancel' => 'Cancel', 'saved' => 'Saved.', 'save' => 'Save', 'confirm' => 'Confirm',];
As you can see, there are two separate files right now. Both of them have to be sent to our translator, with these instructions:
=>
sign.=>
sign the same.\
before '
sign if it's in the text.Imagine giving this set of instructions to a person who doesn't know anything about programming. It's not easy, right?
It's even harder if you have a lot of files (for example validation files) and a lot of text to translate.
You also may have an issue where the translator wouldn't understand the meaning or intention of the key, as it's not quite clear what the context is. You might have more specific keys but that doesn't help much.
You might have noticed that we didn't talk about the core Laravel translation files, such as lang/en/validation.php
. That's because you don't usually have to translate them yourself.
There's an awesome community-built translation repository: Laravel-Lang/lang
They have a full package that adds some commands to your project:
composer require laravel-lang/common --dev
php artisan lang:add es
to install the language files for es
(Spanish).That's it! You now have the Spanish language files installed in your project. You can extend this by adding any additional keys that you might have in your project.
You can also copy files manually if you wish:
es
: https://github.com/Laravel-Lang/lang/tree/main/locales/es
json.json
file and copy its contents of it.lang/es.json
json.json
file into your new file.That's it. You should be good to go.
Heard of ChatGPT yet?
So yeah, you may not need an external translator. If given a correct set of rules, AI can perform the translation for us!
While it's definitely not perfect, it's a good example of how AI could help you translate text one day!
Notice: Each ChatGPT run gave us a different translation for some text, so you'd have to manually fix them or have someone review them.