Open Retaview opened 8 months ago
Does anyone have a .json file already created to share? I don't mind the language. It's just that on such a complex server like this, it's very complicated to know every button or text that needs translation. If you have one made in another language that only needs to be changed to Spanish, I would appreciate it.
Guide: Implementation of a Multilanguage Translation System
Many people adore Nemesus World Server, however, not everyone speaks German or intends to create a server in German. That's why I want to explain step by step how to create a multilanguage translation system. First we will focus on the server interfaces (vuejsserver), then we will focus on the backend. To do this, we need to modify the
main.js
file inside the /vuejsserver/src folder by adding the following code:After updating the
main.js
file, we need to create a folder called "locales" inside /vuejsserver/src, we add the languages we want to translate the interfaces to, in addition to the original language, German. In my case, I have created 3 languages:de.json
,en.json
, andes.json
. Within each of those files, we add the keys along with the translations.After that, we simply access the
.vue
components inside the /vuejsserver/src/components folder and change all the texts to keys.For example, in the
Login.vue
file, we change this piece of code:To the following:
And then we add the text that was in
de.json
:We also do the same with the rest of the
.json
files in /vuejsserver/src/locales. For example, for Spanish, we would put the following ines.json
:As you can see, we are organizing everything by categories, which correspond to the file. For example, since we are modifying the
Login.vue
file, we add all those translations in the login category, and in the key, we put it in this way:{{ $translations.login.button1 }}
. If we modify another file, we will change the name of the category to the name of the file. For example, forRegister.vue
, it would be{{ $translations.register.name }}
, and the.json
file would look like this:To translate placeholders, we need to make a small change, which will be according to the following structure
:placeholder="$translations.login.password"
instead of simplyplaceholder= "Text"
. In summary, we need to add ":" beforeplaceholder
and use quotes instead of{}
, for the rest, we add the keys exactly the same to the.json
files like the others. Functions withthis.warning
must be changed as follows:this.warning = this.$translations.login.shortWarning;
. We must always change both the category (login) and the keys (password
in the example of the previous placeholder orshortWarning
in the case of thethis.warning
function). For example, our JSON file would still look like this:To choose the language that will be displayed on the server, we must change the string of the
changeLanguage('en');
option inmain.js
with the language we want to display. Once we have made changes, we must runnpm run build
within the /vuejsserver directory and then start the server as usual. If you followed the instructions, you should see the server with the language completely changed.Creating a Multilanguage Translation System for the backend
We have already created a multilanguage translation system for the interfaces (vuejsserver), but we still need to create a translation system for the backend. To do this, we simply need to create a new file called
Translator.cs
inside the folder /backend/NemesusWorld/Utils and paste the following content:Once the file is created, we will open each C# file that we want to translate and replace the strings with the following function
Translator.Translate("backend", "name"));
, then we will add the text in the same.json
files that we use for the interface translations, that isde.json
,en.json
, andes.json
. For example, we could change this:to this:
and add the following in, for example,
es.json
:As you can see, we have added the category first and then the key name in the C# code. This way we have all the translations in the same files globally and easy to translate. To change the default language displayed, we must change
private static string defaultLang = "en";
to the language we want to load. Finally, we will rebuild the entire solution and we can start the server with the changes applied.