configurable application texts
My application is shipped to many different customers, who all want to have control on the texts that the application displays (for example- one customer wants to display 'the operation completed successfuly', the other 'operation completed' and another 'tres bien').
So basically the requirement here is to allow the customer to edit those things 'on the fly' via a GUI. In the future, we might want to add the option of 'placeholders' (i.e开发者_高级运维. 'operation {0} completed' where {0} is the ID of the operation.)Is there any framework / common practise for dealing with this issue?
I'm guessing this is a very common issue, but I haven't been able to find any resources about it.(I'm using ASP.Net and nHibernate for my ORM.)
My best idea so far is to have a table in the db for all messages, and implement some management mechanism for it. Further ideas would be appriciated.There are quite a few answers to this around on SO. Essentially there is not standard way of doing it and it is usually a mix between elements in the database and other elements tagged with text files of some sort. There is GNU gettext, there is xliff etc see here for a list As well as the pure translation there are aspects of colour and typography. Anglo Saxons like san serif and cool colours, Spanish speaking nations like serif fonts and warmer colours. (not my stereotyping) and so on. Non english languages, especially the romance languages tend to be about 30% longer than the equivalent english text so layout needs to be flexible and TESTED. Many languages are right to left and some, Japanese for one do not have white space.
Read on and welcome to the minefield.
There are a few books on the subject but not that good.
Why don't you use the .NET built-in capability to read from ressource assemblies?
So you can handle for each language (or customer) an own resource assembly. You can translate their content e.g. with http://www.sisulizer.com/ or another 3rd party application. Then each customer can translate or write his text itself.
Kind regards, patrick
btw: http://www.sisulizer.com can also translate data tables in a db :-)
Ok, this is the solution I've ended up with (not the best solution possible, I'm sure, but flexible enough for my needs):
Since all the operation results in my businees layer are represented by enums anyway (for example- EmployeeAddition.SameNameExists
or DepartmentDeletion.DepartmentNotEmpty
), it was fairly simple to create an entity class which describes the text messages related to those enums:
public class ConfigurableText : Entity
{
public virtual int TextId { get; private set; }
public virtual TextType TypeOfText { get; set; }
public virtual int EnumValue { get; set; }
public virtual string MainLanguageText { get; set; }
public virtual string SecondaryLanguageText { get; set; }
public virtual string Description { get; set; }
public ConfigurableText()
{
TypeOfText = ConfigurableText.TextType.PassengerMessage;
EnumValue = 0;
Description = string.Empty;
TextId = GetTextId(TypeOfText, EnumValue);
}
public ConfigurableText(TextType type, int enumValue,string mainLanguageText,string description) : this()
{
TypeOfText = type;
EnumValue = enumValue;
MainLanguageText = mainLanguageText;
Description = description;
TextId = GetTextId(TypeOfText, EnumValue);
}
public ConfigurableText(TextType type, int enumValue,string mainLanguageText, string description, string secondaryLanguageText) : this(type,enumValue,mainLanguageText,description)
{
SecondaryLanguageText = secondaryLanguageText;
}
public enum TextType
{
EmployeeMessage = 1,
DepartmentDeletionMessage,
//...
}
public static int GetTextId(TextType type, int enumValue)
{
return int.Parse(((int)type).ToString() + "00"
+ enumValue.ToString() + "00");
}
}
and then, client application just goes:
var ctrl = new TextsManagementController();
ConfigurableTextPO message = ctrl.GetText(ConfigurableText.TextType.EmployeeMessage, (int)this.Validity);
MessageMainLanguage = message.MainLanguageText;
Since I'm utilizing nHibernate's 2nd level cache, the DB is (almost) never hit, so performance shouldn't be an issue.
It's no problem, of course, to build a GUI for updating those entities.
The downside of it is that for every bit of text that i'd like to be able to configure I have to define an enum, and manually retrieve the values when they're needed.
精彩评论