I need to create an Angular app in English and Spanish so I am thinking to use angular localize with i18n. I am reading the documentation but my app has a panel administrator to create rooms update and delete them. I have to create for each component the translation but how to create the translation for the two languages when the administrator creates the rooms?
Asked
Active
Viewed 145 times
0
-
I don't quite understand the question. As far as I understood. The admin can create rooms and for each room, two translations (English and Spanish) should be automatically created. Am I right? If that is the case, then the best solution in my opinion is to create a JSON object with the room id (or similar) as the key and the content will be then both languages. This will make editing, adding new rooms and adding new languages easy. I this case, I don't recommend the angular localize. Rather, build your own translator. It is not that hard to achieve it. – Samy Sammour Jun 12 '21 at 22:25
-
1{ room1: {english: { 'i18n_Name': 'english name', 'i18n_Age': 'english age'}, spanish: { 'i18n_Name': 'spanish name', 'i18n_Age': 'spanish age'}, ... } the selector will be something like: rooms['room1'].english['i18n_Name'] – Samy Sammour Jun 12 '21 at 22:27
-
I am thinking in create two objects per room one in English the other in spanish but when an user click button for traslate in Spanish how to show the Spanish object ? – Rafael Hernández Jun 14 '21 at 15:07
-
Angular is a single page application, which means, the services which are provided in the module (DI) will keep their data and within you can choose which object you want to select the Spanish or English. Another option might be the storages (Local and session storages) or maybe the URL to set the selected language. But what I most recommend is to select the translation on the fly. This means you don't need to select an object, rather you just search inside with the provided language for a specific tag and get the translation out of it (A pipe or something) – Samy Sammour Jun 15 '21 at 15:33