0

In my project (I am using azure storage) I have some data that I want to translate. I have the resource system in place for translations. I have a table in cloud which has name property. I want to translate it somehow.

One option is to create all the entries in database for each language which I don't prefer as it would create a lot entries along with the name.

Is there a smart way to use the resx mechanism I have in place?

So the table has multiple properties and one is name. Name could be anything like Mud, rock etc. Now I want to translate Mud into different language. Something like Texts.Mud would return me the correct value.

But lets say I get data like this

var data = some query;
string translatedName = Texts.data[0].name; // this won't work
Flores
  • 8,226
  • 5
  • 49
  • 81
mohsinali1317
  • 4,255
  • 9
  • 46
  • 85
  • If you are already using resx, why not just add culture-specific resx? For example you have neutral Resources.resx, add Resources.en-us.resx for us-english, Resources.de.resx for german , Resources.fr.resx for french ... There are also software tools available that collect resx from your solution and put it into translation software compatible formats and back. – Fildor Aug 22 '17 at 09:08
  • Yeah I have that, but normally I access the string I want like Texts.AboutUs how would I get that when the data is coming from database? – mohsinali1317 Aug 22 '17 at 09:09
  • What kind of data? Text? Or numbers or dates you want to display culture-specifically? – Fildor Aug 22 '17 at 09:12
  • Its text, I will try to explain it in my question more. – mohsinali1317 Aug 22 '17 at 09:12
  • @Fildor I updated the question. Hope it helps understand my issue. – mohsinali1317 Aug 22 '17 at 09:25
  • Ah, I see. So instead of the name itself, you could store a key into a resx, let's say Names.resx. Then you could use the key from db to get the translated name from the resources file. So would get from db "Name_Mud" and get the value from resourcemanager with that key. – Fildor Aug 22 '17 at 09:28
  • Can you give me a link or something where I could see a working example? – mohsinali1317 Aug 22 '17 at 09:30
  • 1
    https://msdn.microsoft.com/en-us/library/system.resources.resourcemanager(v=vs.110).aspx or https://stackoverflow.com/a/29792476/982149 – Fildor Aug 22 '17 at 09:35

1 Answers1

0

You should instead add more columns in the database, each for a different language and select the column based on the user language. Other solution is to have a transaltion mechanism (a custom class for example), where you pass the original database result (say data[0].name) to a query and it returns the translated value for you.

Lamar
  • 1,761
  • 4
  • 24
  • 50