All translation is create from template NLocalizer\RuntimeCodeTemplates.txt:

; RuntimeTranslation Template (C) Krzysztof Arkadiusz Prusik, NLocalizer.codeplex.com
; $Id: RuntimeCodeTemplates.txt,v 093425a2b93b 2011/04/04 03:12:56 kap $
;
@Code
/*******************************************************************************

  NLocalizer (C) Krzysztof Arkadiusz Prusik, NLocalizer.codeplex.com
  Code file to languages: $(Locales) autogenerated $(DateTime)
  $Id: RuntimeCodeTemplates.txt,v 093425a2b93b 2011/04/04 03:12:56 kap $

*******************************************************************************/

$(Using)
namespace NLocalizer
{
   public static class RuntimeTranslator
   {
        public static void Translate()
        {
            Translate(Translator.Translation);
        }

        public static void Translate(Translation translation)
        {
            Translate(translation.CurrentLanguage, translation);
        }

        public static void Translate(string language, Translation translation)
        {
$(TranslateClass)
	}

        public static void Remember()
        {
            Remember(Translator.Translation);
        }


        public static void Remember(Translation translation)
        {
$(RememberClass)
	}

        public static void Restore()
        {
            Restore(Translator.Translation);
        }

        public static void Restore(Translation translation)
        {
$(RestoreClass)
	}

	public static string GetMacro(string macro)
	{
	    switch (macro)
	    {
$(Macro)
		default:
	            return "";
	    }
	}

$(ClassTranslation)
   }
}

@Using
using ${NamespaceName);
@TranslateClass
            Translate$(ClassName)(language, translation);
@RememberClass
            Remember$(ClassName)(translation);
@RestoreClass
            Restore$(ClassName)(translation);
@StaticClass
        public static void Remember$(ClassName)()
        {
            Remember$(ClassName)(Translator.Translation);
        }

        public static void Remember$(ClassName)(Translation translation)
        {
$(StaticClassRemember)
        }

        public static void Restore$(ClassName)()
        {
            Restore$(ClassName)(Translator.Translation);
	}

        public static void Restore$(ClassName)(Translation translation)
        {
            if (translation.Exists("Neutral", "$(ClassName)"))
                Translate$(ClassName)("Neutral", translation);
        }

        public static void Translate$(ClassName)(string language)
        {
            Translate$(ClassName)(language, Translator.Translation);
        }

        public static void Translate$(ClassName)(string language, Translation translation)
        {
            if (translation.Exists("Neutral", "$(ClassName)") == false)
                Remember$(ClassName)(translation);

$(StaticClassTranslate)
        }
@StaticClassRemember
            translation.SetProperty("Neutral", "$(ClassName)", "$(PropertyName)", $(ClassName).$(PropertyName), true);
@StaticClassTranslate
            $(ClassName).$(PropertyName) = translation.GetProperty(language, "$(ClassName)", "$(PropertyName)", GetMacro).Message;
@DynamicClass
        public static $(ClassName) Create$(ClassName)()
        {
            return new $(ClassName)();
        }

        public static void Remember($(ClassName) obj)
        {
            Remember(obj, Translator.Translation);
        }

        public static void Remember($(ClassName) obj, Translation translation)
        {
$(DynamicClassRemember)
			Remember(translation);
        }

        public static void Restore($(ClassName) obj)
        {
            Restore(obj, Translator.Translation);
        }

        public static void Restore($(ClassName) obj, Translation translation)
        {
            if (translation.Exists("Neutral", "$(ClassName)"))
                Translate("Neutral", obj, translation);
        }

        public static void Translate(string language, $(ClassName) obj)
        {
            Translate(language, obj, Translator.Translation);
        }

        public static void Translate(string language, $(ClassName) obj, Translation translation)
        {
            if (translation.Exists("Neutral", "$(ClassName)") == false)
                Remember(obj, translation);

	    Translate(language, translation);

$(DynamicClassTranslate)
        }
@DynamicClassRemember
            translation.SetProperty("Neutral", "$(ClassName)", "$(PropertyName)", obj.$(PropertyName), false);
@DynamicClassTranslate
            obj.$(PropertyName) = translation.GetProperty(language, "$(ClassName)", "$(PropertyName)", GetMacro).Message;
@Macro
		case "$(MacroName)":
			return $(MacroCode);

if Your application is started, and when Translator.Translate method will be first time executed NLocalizer is generate class like this and compile it at runtime with Your application:

/*******************************************************************************

  NLocalizer (C) Krzysztof Arkadiusz Prusik, NLocalizer.codeplex.com
  Code file to languages: en-GB, en-US, pl-PL autogenerated 2011-04-02
  $Id: RuntimeTranslator.cs,v 093425a2b93b 2011/04/04 03:12:56 kap $

*******************************************************************************/

using Microsoft.VisualStudio.TestTools.Resources;
using NLocalizer.Tests;
using System.Windows.Forms;

namespace NLocalizer
{
   public static class RuntimeTranslator
   {
        public static void Translate()
        {
            Translate(Translator.Translation);
        }

        public static void Translate(Translation translation)
        {
            Translate(translation.CurrentLanguage, translation);
        }

        public static void Translate(string language, Translation translation)
        {
            TranslateMessages(language, translation);
	}

        public static void Remember()
        {
            Remember(Translator.Translation);
        }

        public static void Remember(Translation translation)
        {
            RememberMessages(translation);
	}

        public static void Restore()
        {
            Restore(Translator.Translation);
        }

        public static void Restore(Translation translation)
        {
            RestoreMessages(translation);
	}

        public static void RememberMessages()
        {
            RememberMessages(Translator.Translation);
        }

        public static void RememberMessages(Translation translation)
        {
            translation.SetProperty("Neutral", "Messages", "TestMessage", Messages.TestMessage, true);

        }

        public static void RestoreMessages()
        {
            RestoreMessages(Translator.Translation);
	}

        public static void RestoreMessages(Translation translation)
        {
            if (translation.Exists("Neutral", "Messages"))
                TranslateMessages("Neutral", translation);
        }

        public static void TranslateMessages(string language)
        {
            TranslateMessages(language, Translator.Translation);
        }

        public static void TranslateMessages(string language, Translation translation)
        {
            if (translation.Exists("Neutral", "Messages") == false)
                RememberMessages(translation);
            Messages.TestMessage = translation.GetProperty(language, "Messages", "TestMessage", GetMacro).Message;
        }
        public static TestForm CreateTestForm()
        {
            return new TestForm();
        }

        public static void Remember(TestForm obj)
        {
            Remember(obj, Translator.Translation);
        }

        public static void Remember(TestForm obj, Translation translation)
        {
            translation.SetProperty("Neutral", "TestForm", "label1.Text", obj.label1.Text, false);
            translation.SetProperty("Neutral", "TestForm", "linkLabel1.Text", obj.linkLabel1.Text, false);
            translation.SetProperty("Neutral", "TestForm", "tabPage1.Text", obj.tabPage1.Text, false);
            translation.SetProperty("Neutral", "TestForm", "tabPage2.Text", obj.tabPage2.Text, false);
            translation.SetProperty("Neutral", "TestForm", "Text", obj.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripButton1.Text", obj.toolStripButton1.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripButton2.Text", obj.toolStripButton2.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripButton3.Text", obj.toolStripButton3.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripButton4.Text", obj.toolStripButton4.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem1.Text", obj.toolStripMenuItem1.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem10.Text", obj.toolStripMenuItem10.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem2.Text", obj.toolStripMenuItem2.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem3.Text", obj.toolStripMenuItem3.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem4.Text", obj.toolStripMenuItem4.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem5.Text", obj.toolStripMenuItem5.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem6.Text", obj.toolStripMenuItem6.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem7.Text", obj.toolStripMenuItem7.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem8.Text", obj.toolStripMenuItem8.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripMenuItem9.Text", obj.toolStripMenuItem9.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripStatusLabel1.Text", obj.toolStripStatusLabel1.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripStatusLabel2.Text", obj.toolStripStatusLabel2.Text, false);
            translation.SetProperty("Neutral", "TestForm", "toolStripTextBox2.Text", obj.toolStripTextBox2.Text, false);

	    Remember(translation);
        }

        public static void Restore(TestForm obj)
        {
            Restore(obj, Translator.Translation);
        }

        public static void Restore(TestForm obj, Translation translation)
        {
            if (translation.Exists("Neutral", "TestForm"))
                Translate("Neutral", obj, translation);
        }

        public static void Translate(string language, TestForm obj)
        {
            Translate(language, obj, Translator.Translation);
        }

        public static void Translate(string language, TestForm obj, Translation translation)
        {
            if (translation.Exists("Neutral", "TestForm") == false)
                Remember(obj, translation);

            obj.label1.Text = translation.GetProperty(language, "TestForm", "label1.Text", GetMacro).Message;
            obj.linkLabel1.Text = translation.GetProperty(language, "TestForm", "linkLabel1.Text", GetMacro).Message;
            obj.tabPage1.Text = translation.GetProperty(language, "TestForm", "tabPage1.Text", GetMacro).Message;
            obj.tabPage2.Text = translation.GetProperty(language, "TestForm", "tabPage2.Text", GetMacro).Message;
            obj.Text = translation.GetProperty(language, "TestForm", "Text", GetMacro).Message;
            obj.toolStripButton1.Text = translation.GetProperty(language, "TestForm", "toolStripButton1.Text", GetMacro).Message;
            obj.toolStripButton2.Text = translation.GetProperty(language, "TestForm", "toolStripButton2.Text", GetMacro).Message;
            obj.toolStripButton3.Text = translation.GetProperty(language, "TestForm", "toolStripButton3.Text", GetMacro).Message;
            obj.toolStripButton4.Text = translation.GetProperty(language, "TestForm", "toolStripButton4.Text", GetMacro).Message;
            obj.toolStripMenuItem1.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem1.Text", GetMacro).Message;
            obj.toolStripMenuItem10.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem10.Text", GetMacro).Message;
            obj.toolStripMenuItem2.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem2.Text", GetMacro).Message;
            obj.toolStripMenuItem3.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem3.Text", GetMacro).Message;
            obj.toolStripMenuItem4.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem4.Text", GetMacro).Message;
            obj.toolStripMenuItem5.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem5.Text", GetMacro).Message;
            obj.toolStripMenuItem6.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem6.Text", GetMacro).Message;
            obj.toolStripMenuItem7.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem7.Text", GetMacro).Message;
            obj.toolStripMenuItem8.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem8.Text", GetMacro).Message;
            obj.toolStripMenuItem9.Text = translation.GetProperty(language, "TestForm", "toolStripMenuItem9.Text", GetMacro).Message;
            obj.toolStripStatusLabel1.Text = translation.GetProperty(language, "TestForm", "toolStripStatusLabel1.Text", GetMacro).Message;
            obj.toolStripStatusLabel2.Text = translation.GetProperty(language, "TestForm", "toolStripStatusLabel2.Text", GetMacro).Message;
            obj.toolStripTextBox2.Text = translation.GetProperty(language, "TestForm", "toolStripTextBox2.Text", GetMacro).Message;

        }

	public static string GetMacro(string macro)
	{
	    switch (macro)
	    {
case "Application.ProductTitle":
return Application.ProductTitle;
 default: return ""; } } } }

You can change templates by RuntimeCompiler.CodeTemplatesAsText property. You can also change every template by RuntimeCompiler.CodeTemplates property wich is Dictionary (name of template, value of template). See also: Diagnostic.

Last edited Sep 3, 2011 at 5:22 PM by KAP, version 18

Comments

No comments yet.