Exemple #1
0
        public Localizer(Control rootControl, GettextResourceManager catalog, ObjectPropertiesStore originalTextStore)
        {
            this.Catalog           = catalog;
            this.OriginalTextStore = originalTextStore;
            this.root = rootControl;

            // Access to form components
            // Try access by container
            IterateControls(root,
                            delegate(Control control) {
                InitFromContainer(control.Container);
            });
            // Access by private member
            for (Control c = root; c != null; c = c.Parent)
            {
                if (c is Form || c is UserControl)
                {
                    FieldInfo fi = c.GetType().GetField("components", BindingFlags.NonPublic | BindingFlags.Instance);
                    if (fi != null)
                    {
                        InitFromContainer((IContainer)fi.GetValue(c));
                    }
                }
            }
        }
        public MainController()
        {
            //Type t = typeof(MainCatalog_ru_RU);

            View                 = new UIView();
            View.Frame           = new RectangleF(0f, 0f, 320f, 460f);
            View.BackgroundColor = UIColor.White;

            UILabel l = new UILabel();

            l.Frame         = new RectangleF(0f, 0f, 320f, 200f);
            l.Lines         = 0;
            l.LineBreakMode = UILineBreakMode.WordWrap;

            View.AddSubview(l);

            CultureInfo ci = new CultureInfo("ru-RU");

            GettextResourceManager catalog = new GettextResourceManager("MainCatalog", new DifferentNamesSingleFolderPathResolver());

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(catalog.GetString(Text.MyNameIs, ci))
            .AppendLine(catalog.GetString(Text.MyAge, ci))
            .AppendLine(catalog.GetString(Text.ILove, ci));

            for (int i = 0; i < 6; i++)
            {
                sb.AppendLine(string.Format(catalog.GetPluralString(Text.PluralDay, Text.PluralDays, i, ci), i));
            }

            l.Text = sb.ToString();
        }
Exemple #3
0
        /// <summary>
        /// initialise the resource manager with the given language
        /// </summary>
        public static void Init(string ALanguageCode, string ACultureCode)
        {
            if (ALanguageCode.ToLower() == "en-en")
            {
                ALanguageCode = "en-GB";
            }

            if (ACultureCode.ToLower() == "en-en")
            {
                ACultureCode = "en-GB";
            }

            // modify current locale for the given language
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ALanguageCode);

#if USE_GETTEXT_RESOURCEDLL
            string ResourceDllFname = TAppSettingsManager.ApplicationDirectory +
                                      Path.DirectorySeparatorChar +
                                      Thread.CurrentThread.CurrentUICulture.Name +
                                      Path.DirectorySeparatorChar +
                                      "OpenPetra.resources.dll";

            if (File.Exists(ResourceDllFname))
            {
                catalog = new GettextResourceManager("OpenPetra",
                                                     TAppSettingsManager.ApplicationDirectory);
            }
            else
            {
                TLogging.LogAtLevel(1, "cannot find " + ResourceDllFname);
            }
#endif

            Thread.CurrentThread.CurrentCulture = new CultureInfo(ACultureCode);
        }
Exemple #4
0
        private void SetTexts()
        {
            GettextResourceManager catalog = new GettextResourceManager(PathResolver.Default);

            // If satellite assemblies have another base name use GettextResourceManager("Examples.HelloForms.Messages") constructor
            // If you call from another assembly, use GettextResourceManager(anotherAssembly) constructor
            Localizer.Localize(this, catalog, store);
            // We need pass 'store' argument only to be able revert original text and switch languages on fly
            // Common use case doesn't required it: Localizer.Localize(this, catalog);

            // Manually formatted strings
            label2.Text = catalog.GetStringFmt("This program is running as process number \"{0}\".",
                                               System.Diagnostics.Process.GetCurrentProcess().Id);
            label3.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 1),
                1);
            label4.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 2),
                2);
            label5.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 5),
                5);
            label6.Text = String.Format("{0} ('computers')", catalog.GetParticularString("Computers", "Text encoding"));
            label7.Text = String.Format("{0} ('military')", catalog.GetParticularString("Military", "Text encoding"));
            label8.Text = String.Format("{0} (non contextual)", catalog.GetString("Text encoding"));
        }
Exemple #5
0
        /// <summary>
        /// initialise the resource manager with the given language
        /// </summary>
        public static void Init(string ALanguageCode, string ACultureCode)
        {
            if (ALanguageCode.ToLower() == "en-en")
            {
                ALanguageCode = "en-GB";
            }

            if (ACultureCode.ToLower() == "en-en")
            {
                ACultureCode = "en-GB";
            }

            // modify current locale for the given language
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ALanguageCode);

            string ResourceDllFname = TAppSettingsManager.ApplicationDirectory +
                                      "\\" + Thread.CurrentThread.CurrentUICulture.IetfLanguageTag + "\\OpenPetra.resources.dll";

            if (File.Exists(ResourceDllFname))
            {
                catalog = new GettextResourceManager("OpenPetra");
            }
            else
            {
                TLogging.LogAtLevel(1, "cannot find " + ResourceDllFname);
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo(ACultureCode);
        }
Exemple #6
0
        static void ShowMessages()
        {
            Console.WriteLine("Current culture {0}", System.Threading.Thread.CurrentThread.CurrentUICulture);
            GettextResourceManager catalog = new GettextResourceManager();

            Console.WriteLine(catalog.GetString("Hello, world!"));
            // GetStringFmt is an Gettext.NET extension
            Console.WriteLine(catalog.GetStringFmt("This program is running as process number \"{0}\".",
                                                   Process.GetCurrentProcess().Id));
            Console.WriteLine(String.Format(
                                  catalog.GetPluralString("found {0} similar word", "found {0} similar words", 1),
                                  1));
            // GetPluralStringFmt is an Gettext.NET extension
            Console.WriteLine(catalog.GetPluralStringFmt("found {0} similar word", "found {0} similar words", 2));
            Console.WriteLine(String.Format(
                                  catalog.GetPluralString("found {0} similar word", "found {0} similar words", 5),
                                  5));

            Console.WriteLine("{0} ('computers')", catalog.GetParticularString("Computers", "Text encoding"));
            Console.WriteLine("{0} ('military')", catalog.GetParticularString("Military", "Text encoding"));
            Console.WriteLine("{0} (non cotextual)", catalog.GetString("Text encoding"));

            Console.WriteLine(catalog.GetString(
                                  "Here is an example of how one might continue a very long string\nfor the common case the string represents multi-line output.\n"));
        }
        private void LocalizeProperty(GettextResourceManager catalog, string propertyName)
        {
            string text = GetPropertyValue(propertyName);

            if (text != null)
            {
                SetPropertyValue(propertyName, catalog.GetString(text));
            }
        }
        public void NamesExtractionTest()
        {
            string n1 = "One.Two.Three";

            Assert.AreEqual("Three", GettextResourceManager.ExtractClassName(n1));
            Assert.AreEqual("One.Two", GettextResourceManager.ExtractNamespace(n1));

            Assert.AreEqual("Class", GettextResourceManager.ExtractClassName("Class"));
            Assert.AreEqual(String.Empty, GettextResourceManager.ExtractNamespace(".Test"));
        }
Exemple #9
0
        public static void Localize(Control control, GettextResourceManager catalog, ObjectPropertiesStore originalTextStore)
        {
            if (catalog == null)
            {
                return;
            }
            Localizer loc = new Localizer(control, catalog, originalTextStore);

            loc.Localize();
        }
Exemple #10
0
 public static MPManager Instance()
 {
     if (localUser == null)
     {
         Catalog   = new GettextResourceManager("Orts.Simulation");
         Random    = new Random();
         localUser = new MPManager();
     }
     return(localUser);
 }
Exemple #11
0
    public static void Main(String[] args)
    {
        GettextResourceManager catalog =
            new GettextResourceManager("hello-csharp");

        Console.WriteLine(catalog.GetString("Hello, world!"));
        Console.WriteLine(
            String.Format(
                catalog.GetString("This program is running as process number {0}."),
                Process.GetCurrentProcess().Id));
    }
Exemple #12
0
        public AssemblyGen(Options options)
        {
            sw           = new StringWriter();
            cw           = new IndentedTextWriter(sw);
            this.Options = options;
            ClassName    = GettextResourceManager.MakeResourceSetClassName(Options.BaseName, Options.Locale);
//            CsharpSourceFileName = Path.Combine(
//				Options.OutDir,
//                String.Format("{0}.{1}.resources.cs", Options.BaseName, Options.Locale.Name));
            CsharpSourceFileName = Path.GetTempFileName();
        }
 /// <seealso cref="GettextResourceManager(string, Assembly)"/>
 private GettextTranslationProvider([NotNull] string baseName, [NotNull] Assembly assembly)
 {
     if (baseName == null)
     {
         throw new ArgumentNullException(nameof(baseName));
     }
     if (assembly == null)
     {
         throw new ArgumentNullException(nameof(assembly));
     }
     resourceManager = new GettextResourceManager(baseName, assembly);
     BaseName        = baseName;
 }
Exemple #14
0
        public TestingForm(UserSettings settings, string runActivity)
        {
            InitializeComponent();  // Needed so that setting StartPosition = CenterParent is respected.

            GettextResourceManager catalog = new GettextResourceManager("Menu");

            Localizer.Localize(this, catalog);

            // Windows 2000 and XP should use 8.25pt Tahoma, while Windows
            // Vista and later should use 9pt "Segoe UI". We'll use the
            // Message Box font to allow for user-customizations, though.
            Font = SystemFonts.MessageBoxFont;

            this.runActivity = runActivity;
            this.settings    = settings;

            UpdateButtons();
        }
Exemple #15
0
        /// <summary>
        ///
        /// </summary>
        public bool ChangeLocale(string Locale)
        {
            bool result = false;

            if (Locale != "")
            {
                string locale = Locale;                 //"en-US";//"fr-FR";
                System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(locale);

                // I think we have to reinitialize this now
                Cat = new GettextResourceManager();
            }
            else
            {
                lg.Instance.Line("Loc.ChangeLocale", ProblemType.ERROR, String.Format("{0} is an invalid Locale", Locale));
            }
            return(result);
        }
Exemple #16
0
        public static string bindtextdomain(string domain, string directory)
        {
            if (domain.Length == 0)
            {
                return(null);
            }

            directory = Path.GetFullPath(directory);

            //directory = Path.Combine(ScriptContext.CurrentContext.WorkingDirectory, directory);

            if (!System.IO.Directory.Exists(directory))
            {
                return(null);
            }

            manager = new GettextResourceManager(domain, directory, "{{resource}}.po");

            return(directory);
        }
Exemple #17
0
        private void Compile()
        {
            Process p = new Process();

            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardInput  = false;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName  = Options.CompilerName;
            p.StartInfo.Arguments = String.Format(
                "-target:library -out:\"{0}/{1}\" -lib:\"{2}\" -reference:GNU.Gettext.dll -optimize+ \"{3}\"",
                AssemblyOutDir,
                GettextResourceManager.GetSatelliteAssemblyName(Options.BaseName),
                Path.GetFullPath(Options.LibDir),
                CsharpSourceFileName
                );
            if (Options.Verbose)
            {
                Console.WriteLine("Compiler: {0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments);
            }
            p.Start();
            p.WaitForExit(30000);
            if (p.HasExited)
            {
                if (p.ExitCode != 0)
                {
                    throw new Exception(String.Format(
                                            "Assembly compilation failed. ExitCode: {0}\nSee source file: {1}\n{2}\n{3}",
                                            p.ExitCode,
                                            CsharpSourceFileName,
                                            p.StandardOutput.ReadToEnd(),
                                            p.StandardError.ReadToEnd()));
                }
            }
            else
            {
                p.Close();
                p.Kill();
                throw new Exception("Assembly compilation timeout");
            }
        }
        public void Localize(GettextResourceManager catalog)
        {
            LocalizeProperty(catalog, "Text");
            LocalizeProperty(catalog, "HeaderText");
            LocalizeProperty(catalog, "ToolTipText");

            if (Source is Control)
            {
                foreach(ToolTip toolTip in ToolTips)
                {
                    string hint = toolTip.GetToolTip(Source as Control);
                    if (hint != null)
                    {
                        StoreIfOriginal("FromToolTipText", hint);
                        string translatedHint = catalog.GetString(hint);
                        if (translatedHint != toolTip.GetToolTip(Source as Control))
                            toolTip.SetToolTip((Source as Control), translatedHint);
                    }
                }
            }
        }
Exemple #19
0
        private void Compile()
        {
            if (File.Exists(GettextResourceManager.GetSatelliteAssemblyName(Options.BaseName)))
            {
                File.Delete(GettextResourceManager.GetSatelliteAssemblyName(Options.BaseName));
            }

            CompilerParameters cp = new CompilerParameters();

            cp.GenerateExecutable      = false;
            cp.OutputAssembly          = GettextResourceManager.GetSatelliteAssemblyName(Options.BaseName);
            cp.IncludeDebugInformation = false;
            cp.ReferencedAssemblies.Add("GNU.Gettext.dll");
            cp.GenerateInMemory = false;
            cp.CompilerOptions  = "-optimize+";

            CSharpCodeProvider Compiler = new CSharpCodeProvider(new Dictionary <string, string>()
            {
                { "CompilerVersion", "v3.5" }
            });
            CompilerResults cr = Compiler.CompileAssemblyFromFile(cp, CsharpSourceFileName);

            if (!cr.Errors.HasErrors)
            {
                if (File.Exists(Path.Combine(AssemblyOutDir, GettextResourceManager.GetSatelliteAssemblyName(Options.BaseName))))
                {
                    File.Delete(Path.Combine(AssemblyOutDir, GettextResourceManager.GetSatelliteAssemblyName(Options.BaseName)));
                }
                File.Move(GettextResourceManager.GetSatelliteAssemblyName(Options.BaseName), Path.Combine(AssemblyOutDir, GettextResourceManager.GetSatelliteAssemblyName(Options.BaseName)));
            }
            else
            {
                String error = "Assembly compilation failed.";
                foreach (CompilerError er in cr.Errors)
                {
                    error += "\n" + cr.Output;
                }
                throw new Exception(error);
            }
        }
        public void Localize(GettextResourceManager catalog)
        {
            LocalizeProperty(catalog, "Text");
            LocalizeProperty(catalog, "HeaderText");
            LocalizeProperty(catalog, "ToolTipText");

            if (Source is Control)
            {
                foreach (ToolTip toolTip in ToolTips)
                {
                    string hint = toolTip.GetToolTip(Source as Control);
                    if (hint != null)
                    {
                        StoreIfOriginal("FromToolTipText", hint);
                        string translatedHint = catalog.GetString(hint);
                        if (translatedHint != toolTip.GetToolTip(Source as Control))
                        {
                            toolTip.SetToolTip((Source as Control), translatedHint);
                        }
                    }
                }
            }
        }
 public void Ex3Test()
 {
     GettextResourceManager.ExtractClassName("Class.");
 }
Exemple #22
0
        private void SetTexts()
        {
            GettextResourceManager catalog = new GettextResourceManager(PathResolver.Default);
            // If satellite assemblies have another base name use GettextResourceManager("Examples.HelloForms.Messages") constructor
            // If you call from another assembly, use GettextResourceManager(anotherAssembly) constructor
            Localizer.Localize(this, catalog, store);
            // We need pass 'store' argument only to be able revert original text and switch languages on fly
            // Common use case doesn't required it: Localizer.Localize(this, catalog);

            // Manually formatted strings
            label2.Text = catalog.GetStringFmt("This program is running as process number \"{0}\".",
                                               System.Diagnostics.Process.GetCurrentProcess().Id);
            label3.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 1),
                1);
            label4.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 2),
                2);
            label5.Text = String.Format(
                catalog.GetPluralString("found {0} similar word", "found {0} similar words", 5),
                5);
            label6.Text = String.Format("{0} ('computers')",  catalog.GetParticularString("Computers", "Text encoding"));
            label7.Text = String.Format("{0} ('military')",  catalog.GetParticularString("Military", "Text encoding"));
            label8.Text = String.Format("{0} (non contextual)",  catalog.GetString("Text encoding"));
        }
Exemple #23
0
 static string ToMsgid(CatalogEntry entry)
 {
     return(ToConstStr(
                entry.HasContext ?
                GettextResourceManager.MakeContextMsgid(entry.Context, entry.String) : entry.String));
 }
 private void LocalizeProperty(GettextResourceManager catalog, string propertyName)
 {
     string text = GetPropertyValue(propertyName);
     if (text != null)
         SetPropertyValue(propertyName, catalog.GetString(text));
 }
 public void Ex2Test()
 {
     GettextResourceManager.ExtractClassName(String.Empty);
 }
Exemple #26
0
 public Localizer(Control rootControl, GettextResourceManager catalog)
     : this(rootControl, catalog, null)
 {
 }
 public void Ex1Test()
 {
     GettextResourceManager.ExtractClassName(null);
 }
Exemple #28
0
 public static void Localize(Control control, GettextResourceManager catalog)
 {
     Localizer.Localize(control, catalog, null);
 }
Exemple #29
0
 public Loc()
 {
     Cat = new GettextResourceManager();
 }