November Happy Hour will be moved to Thursday December 5th.

Log non translated texts

Vote:
 

Is there any way to log non translated texts in EPiServer?

/Jonas

 

 

#57375
Mar 13, 2012 8:13
Vote:
 

Hi, 

Looking at the Translate methods in EPiServer.Core.LanguageManager, you can see that the "[Missing text ...]" string is hardcoded as a return value if a text hasn't been translated: 

public string Translate(string key, string language)
{
    string str = this.TranslateRaw(key, language);
    if (str == null)
    {
        return ("[Missing text " + key + " for " + language + "]");
    }
    return str;
}

    

So what you could do is create your own Translate method that calls LanguageManager.Instance.Translate (and the overload methods if you're using those), and checks if the return value contains "[Missing text...]". If so, log the non translated text:

public static class MyLanguageManager
    {
        public static string Translate(string key)
        {
            string translatedText = LanguageManager.Instance.Translate(key);
            if (!string.IsNullOrEmpty(translatedText) && translatedText.StartsWith("[Missing text ")) // Or you can use Regex
                Logger.Debug(translatedText);
            return translatedText;
        }
    }

Now, instead of calling LanguageManager.Instance.Translate(...) or BasePage.Translate(...) elsewhere in your code, you call MyLanguageManager.Translate(...) instead.

I hope this helps!

Karoline

#57771
Mar 27, 2012 12:39
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.