we have okay it’s an offer in town and so we created our model and let’s try to use it okay let’s go to our application objects and herewe have our application so let’s import let’s import our provider let’s import this provider also we will import all languages you we have and what we need to we need to wrap thewhole application into this provider so let’s use it from here and here Oh what income and so we need the passive language so it will be local and let’suse just English for now then we will change it to see results okay let’scheck is urgent works fine okay.
Let’s open rule application it seems works fine but right now we have no changes okay to use some changes let’s import let’s add translate the hello world as a whole so we need import so we need formatted message component which is used is using for formatting is that translating our text so that’s muted the main props it accepts his ID and let’s add the ID and it will be whole it is key for our for our messages so we have messages English hello and here we will use our hello Kentucky let’s close it and check what do we have here so we have home so here we pass a key but in our message hello is uppercase the first letter and it works to check how it works let that’s okay let’s split our screen to see how it works either so in other objects let’s change language for example for French compile and check result so it here is the bunched so week now we can translate the first one okay so we can see that these format message works but it’s not the goodly gear to use it everywhere Solet’s create some small wrapper and it will simplify our life so here.
We also create new file into a coal translate and here this file vehicle will create our eat you for translation so here we need import react also we need impulses for multi message from rock into and you will create function which is called no slide and prompt you the ID and it will return this formatted message with a dream team and then we can export it and in our application we can use it import you input this function and here instead of using this component and importing it everywhere we can just call our translate function and pass parameter the first part is ID and which will be hello so we can remove it.
We don’t need it anymore and check so here we see that result is the same so everything works great okay so let’s translate this section here we have interesting part it’s inside the translation we have some variable or some see what can be changed so reacting to provide such functionality we can pass it another parameter here for through side function here we can pass another parameter and it will be different wells what action would can be changed so let’s edit the value for the fault well it’s empty object and values so will you trust the destruct well it’s what we received and let’s try to do it lets copy this text and we will add it to our messages so let’s go to English create new key for example edit and we will add this part but here it’s part what should be changed let’s swap it to special color braces and here it should be some name path it is value variable what we are going to use it will be replaced with data you will pass here and let’s copy and add everywhere so in German it will be this part same Google Translate and again copy and install some French language and in the Frenchie tube same but change pants and if you don’t forget Beth okay great and let’s try to change this part okay we go to our application here we have this section let’s check recall our function translate.
The first parameter its key its edit and the second one its object with the value well as well will be the whole components we can use our code we need it might be real component not just the text okay let’s check or not well so we create variable pass so we need name as a path the chip okay we see that for French language we have translated text okay here we can just add its little bit okay so we create a transnational also what we need we need to change this language and let’s create a couple patterns which will help us to change language on the fly so we need here we can create click in separator and bottom English and unclick we want to change this language how can we change it we will save this local or care in our state and for this we will use new state hook this states we will create the cones to volcano set or pail it’s a punch which will change our state and use state so and here we need to pass the fault fail default value will be locals English okay and so on unclick we want to it good function and we won’t set okay and for implicit RIBAlocals English okay let’s copy and put your money to German and French it will be French so now when we click on button we will call set to kill function and to change this local state now we can use just we need you just it here.
So what does it works it change sort state set your set language what you need and we pass it to provider right now we pass it directly in here directly by clicking on bottom and path to provider but in the future we can change it save this language to context API it will storage photos the whole application and then we can use it everywhere where we want okay let’s check how it works so as a result we have three buttons and if we click English we have the same English text if we click German we have German text translated here and here and for French so it works Arius everywhere the same so right now we implement this functionality and it works okay also what I want to show you that how can we use it in another components for example we have some inside companies and we don’t want to pass provider or we do not need to pass any for what message from what did the messages component we can just create new component ok let’s create some for that report due to blue report yes doesn’t matter it will be its just the reactor plication is created first so it’s very simple component okay let’s export it and bring out location we can import and check how it works you can add it here below the limit so a report right now it doesn’t work for translation let’s change it again let’s go to our report and don’t we need function translate from sleep this part we will replace which translate key we built port okay.
We have no such key let’s add it to our messages let’s go to English enjoyment here that’s what that’s before German or French it’s beautiful French okay let’s check so here we see that when we change language this actually is changed also so it works fine and it won’t be expected and if you take a look on this component again so we have no props we have no intel translation model imported we have nothing just translate what we need and here it’s a result of our application so let’s sum it up and check what we implemented so we have application.
we have the whole package is wrapped in provider IAT and provider which receives language what we are going to use and it will say our site will be shown on this language okay sowed have buttons to change your language you can believe or something else or youkan save this in storage and use user agent to get location and set data by default set translation by default so we can change this language and we have false and translated it’s a wrapper for it’s a wrap for formatting message component which receives idea because the parameter ID it’s a key for our translation and the second one is cell value so we can pass any different values here so for example if you have some dynamic text with some calculated fields you can pass it as a second parameter and it will work also we have messages for free languages but we can add as many as we want and just edit here export so right now it works what as we expected.