FarbodKain
FarbodKain

Reputation: 229

what is best way to add another language to laravel website?

i created new website by laravel in ENG language and working perfectly, right now i decide to add another language.i searching in google and find some solution but its not sufficient for me. in all solutions,just translated a few word to another language ( for example "Hello" = > "Hallo" ) and these solutions good for interface (UI),using it like words in admin panel or something like that. but i try to find best way to display my content ( long text or bullet list) in another language.

Upvotes: 0

Views: 2401

Answers (2)

Tim Sheehan
Tim Sheehan

Reputation: 4014

Have a look at the documentation for localization which you can find here https://laravel.com/docs/5.4/localization

The premise of localization is that rather than writing your content directly into a view you would store it in a language config file which can be switched depending on what language you want to display.

E.g.

/resources/lang/en/headings.php

return [
    'welcome' => 'Welcome to my website!'
];

Your view:

<h1>{{ __('headings.welcome') }} or @lang('headings.welcome')</h1>

You then create new language files within other folders using their country code, e.g. /resources/lang/es/headings.php and use App::setLocale($locale); to define which language to use.

Upvotes: 0

R and D Infotech
R and D Infotech

Reputation: 26

I would suggest that you use more than one file per language; structure it in different files per category (i.e.: user, errors, admin, ...). Whatever suits you best.

Of course you could manage all these files in a text-editor or an IDE. But that would involve a process that may look like:

1 You exporting [language][1] files to some format for 'non technical' people.
2 You sending this file to translators.
3 Translator translating.
4 Translator sending translated file back.
5 You putting translations back into a file that's accepted by Laravel.

Upvotes: 1

Related Questions