That ' s it. I find that there are too few laravel on the Internet. A lot of things need to be done by ourselves. To understand.
One of my methods is to go to GitHub to download the Laravel website written by the foreigner, and then take it to run, analyze the code, and then find out where it's going to be. Well, that's a great way to do it. Today I found a good thing, that is, the function of Laravel localization language.
The so-called localized language, which means that different languages may be used in different countries. If you don't have a program that adapts to each language, it means that the program needs to be rewritten. Now Laravel offers a handy feature for localized language support.
Well, let's take a look at these magical features.
Laravel design pattern is a good embodiment of the façade of the design pattern. Encapsulates internal details and exposes a unified interface to the outside.
The localized language here uses the Lang class.
If we want the program to support Chinese and English.
The first step:
In the app directory there is a Lang folder, which has an En folder, which is expressed in English.
We'll set up an zh folder in the inside to indicate Chinese.
Join us in our page to implement such a function
Chinese users show: "Hello, World!"
Users in the United States show: "Hello World"
We have established in EN and zh a name tag.php.
That's what en/tag.php wrote.
Return Array (
"Welcome" = "Hello World"
);
Zh/tag.php wrote in this way:
Return Array (
"Welcome" = "Hello, world"
);
Well, that's the first step we're going to make.
Step Two:
We can see it in our config/app.php.
There's a
' Locale ' = ' en ',//This means that the default is to use the contents of Lang which folder
' Fallback_locale ' = ' en ',//This represents the content in which folder to use if the contents of the above folder do not exist.
Step Three:
It sounds like a big detour. The example below.
In our template page, we wrote
{{Lang::get (' Tag.welcome ')}}
is not very familiar with. Tag means tag.php, and welcome means we return a key name in the array. The data is obtained.
So what is the data in the folder?
Don't ask me about it. It's very clear. Is through the configuration file to get Ah ...
So now if we change the config/app.php configuration file.
' Locale ' = ' en ',
' Fallback_locale ' = ' en ',
Then if we do not find the corresponding content in the zh file, then we will find it in the En folder. If not.
So sorry, the page will show something like Tag.welcome.
Well, this section is complete. I'm going to go on with this.
Persistence makes life valuable.
Best Wishes.