Question

I'm planning to implement a multi language website, so my first ideas were to use the resx files, but I have a requirements to let every text editable from the administration,

can i do such a feature with resx files or should I store them in a database (schemaless) or is there a better way to do this?
Was it helpful?

Solution

you can use xml or sql tables. you should prepare a page for administrator and list all the words for translate. base of language administrator logged on , update the translation of words into your table or xml file. additional , for best performance load each language words to system catch .

write some code like this for entering words into table or xml.

<%=PLang.GetString("YourWordInEnglish")%>

in your aspx

...................

public static string GetString(string word)
    {
        try
        {
            if (String.IsNullOrWhiteSpace(word)) return "";
            Dictionary<string, string> resourcesDictionary = GetResource(GetLanguageID());

            if (resourcesDictionary != null)
            {
                if (!resourcesDictionary.ContainsKey(word.ToLower()))
                {
                    Expression exp = new Expression();
                    exp.Word = exp.Translation = word;
                    exp.LanguageID = GetLanguageID();
                    exp.SiteID = Globals.GetSiteID();
                    if (exp.SiteID == 0 && exp.LanguageID == 0)
                        return word;

                    if (FLClass.createExpression(exp, ref resourcesDictionary) > 0)
                        return resourcesDictionary[word];
                    else
                        return word;

                }
                return resourcesDictionary[word.ToLower()];
            }
            else
                return word;
        }
        catch
        {
            return word;
        }
    }

................... function for edit

 public class ViewExpressionListEdit : BaseWebService
{
    [WebMethod(EnableSession = true)]
    public bool updateExpression(ExpressionService expressionService)
    {
        Expression expression = new Expression();
        expression.ExpressionID = expressionService.ExpressionID;
        expression.Translation = expressionService.Translation;
        expression.LanguageID = expressionService.LanguageID;
        expression.SiteID = Globals.GetSiteID();
        return FLClass.updateExpression(expression);
    }
}

OTHER TIPS

You can use XML files for translations, parse them on application startup and store translations in cache. You can use the FileSystemWatcher class to see when someone updates the files and then invalidate the cache.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top