I have some strings in different languages; for example:
They are captions of buttons that are translated from English to the language chosen from the user.
Which is the best way to compare these captions, programmatically?
Since both the strings are translations of one another you can maintain a translation table and if you want to find out if two strings are same you can just look them up in your table and if they happen to fall in the same row, then they are equal for example
class TranslatedText
{
public int Id {get; set; }
public string Language {get; set; }
public string Text {get; set; }
}
So populate a list of TranslatedText
objects with each string and assign same id to same pieces of text. Later to compare you can lookup the corresponding object in list and check the Id like so
var first = translatedTextList.FirstOrDefault(t=>t.Text.Equals(firstString));
var second = translatedTextList.FirstOrDefault(t=>t.Text.Equals(secondString));
bool areSame = (first != null & second !=null & first.Id == second.Id);
return areSame;
Assuming the strings you want to compare are called firstString
and secondString
;