MO file format parser. See http://www.gnu.org/software/gettext/manual/html_node/MO-Files.html
Exemplo n.º 1
0
 public void TestParsing()
 {
     using (var stream = File.OpenRead(Path.Combine(LocalesDir, Path.Combine("ru_RU", Path.Combine("LC_MESSAGES", "Test.mo")))))
     {
         var parser = new MoFileParser();
         parser.Parse(stream);
         this._TestLoadedTranslation(parser.Translations);
     }
 }
Exemplo n.º 2
0
 public void TestManualEncoding()
 {
     using (var stream = File.OpenRead(Path.Combine(LocalesDir, Path.Combine("ru_RU", Path.Combine("LC_MESSAGES", "Test_KOI8-R.mo")))))
     {
         var parser = new MoFileParser(Encoding.GetEncoding("KOI8-R"), false);
         var parsedFile = parser.Parse(stream);
         this._TestLoadedTranslation(parsedFile.Translations);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
        /// from the specified stream.
        /// </summary>
        /// <param name="moStream"></param>
        /// <param name="pluralRuleGenerator"></param>
        /// <param name="parser"></param>
        public MoLoader(Stream moStream, IPluralRuleGenerator pluralRuleGenerator, MoFileParser parser)
        {
            if (moStream == null)
                throw new ArgumentNullException("moStream");
            if (pluralRuleGenerator == null)
                throw new ArgumentNullException("pluralRuleGenerator");
            if (parser == null)
                throw new ArgumentNullException("parser");

            this._MoStream = moStream;
            this.PluralRuleGenerator = pluralRuleGenerator;
            this.Parser = parser;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
        /// from the specified stream.
        /// </summary>
        /// <param name="moStream"></param>
        /// <param name="pluralRuleGenerator"></param>
        /// <param name="parser"></param>
        public MoLoader(Stream moStream, IPluralRuleGenerator pluralRuleGenerator, MoFileParser parser)
        {
            if (moStream == null)
            {
                throw new ArgumentNullException("moStream");
            }
            if (pluralRuleGenerator == null)
            {
                throw new ArgumentNullException("pluralRuleGenerator");
            }
            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            this._MoStream           = moStream;
            this.PluralRuleGenerator = pluralRuleGenerator;
            this.Parser = parser;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
        /// from the specified path.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="pluralRuleGenerator"></param>
        /// <param name="parser"></param>
        public MoLoader(string filePath, IPluralRuleGenerator pluralRuleGenerator, MoFileParser parser)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }
            if (pluralRuleGenerator == null)
            {
                throw new ArgumentNullException("pluralRuleGenerator");
            }
            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            this._FilePath           = filePath;
            this.PluralRuleGenerator = pluralRuleGenerator;
            this.Parser = parser;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
        /// that will be located in the localeDir using the domain name and catalog's culture info.
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="localeDir"></param>
        /// <param name="pluralRuleGenerator"></param>
        /// <param name="parser"></param>
        public MoLoader(string domain, string localeDir, IPluralRuleGenerator pluralRuleGenerator, MoFileParser parser)
        {
            if (domain == null)
            {
                throw new ArgumentNullException("domain");
            }
            if (localeDir == null)
            {
                throw new ArgumentNullException("localeDir");
            }
            if (pluralRuleGenerator == null)
            {
                throw new ArgumentNullException("pluralRuleGenerator");
            }
            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            this._Domain             = domain;
            this._LocaleDir          = localeDir;
            this.PluralRuleGenerator = pluralRuleGenerator;
            this.Parser = parser;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified path.
 /// <see cref="AstPluralRuleGenerator"/> will be used to generate a plural form rule.
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="parser"></param>
 public MoAstPluralLoader(string filePath, MoFileParser parser)
     : base(filePath, new AstPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 8
0
        /// <summary>
        /// Load translations from given MO file stream using given encoding.
        /// </summary>
        /// <remarks>
        /// By default, parser will try to detect file encoding automatically with fallback to UTF-8 encoding.
        /// If you specify any encoding in this method, auto-detect will be turned off and given encoding will be used instead.
        /// </remarks>
        /// <param name="moStream">Stream that contain binary data in the MO file format</param>
        /// <param name="encoding">File encoding (auto detect by default)</param>
        public void Load(Stream moStream, Encoding encoding = null)
        {
            var parser = new MoFileParser();
            if (encoding != null)
            {
                parser.DetectEncoding = false;
                parser.Encoding = encoding;
            }

            parser.Parse(moStream);

            this.Translations = parser.Translations;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified path.
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="parser"></param>
 public MoLoader(string filePath, MoFileParser parser)
     : this(filePath, new DefaultPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified stream.
 /// </summary>
 /// <param name="moStream"></param>
 /// <param name="parser"></param>
 public MoLoader(Stream moStream, MoFileParser parser)
     : this(moStream, new DefaultPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
        /// from the specified path.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="pluralRuleGenerator"></param>
        /// <param name="parser"></param>
        public MoLoader(string filePath, IPluralRuleGenerator pluralRuleGenerator, MoFileParser parser)
        {
            if (filePath == null)
                throw new ArgumentNullException("filePath");
            if (pluralRuleGenerator == null)
                throw new ArgumentNullException("pluralRuleGenerator");
            if (parser == null)
                throw new ArgumentNullException("parser");

            this._FilePath = filePath;
            this.PluralRuleGenerator = pluralRuleGenerator;
            this.Parser = parser;
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// that will be located in the localeDir using the domain name and catalog's culture info.
 /// </summary>
 /// <param name="domain"></param>
 /// <param name="localeDir"></param>
 /// <param name="parser"></param>
 public MoLoader(string domain, string localeDir, MoFileParser parser)
     : this(domain, localeDir, new DefaultPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// that will be located in the localeDir using the domain name and catalog's culture info.
 /// </summary>
 /// <param name="domain"></param>
 /// <param name="localeDir"></param>
 /// <param name="parser"></param>
 public MoLoader(string domain, string localeDir, MoFileParser parser)
     : this(domain, localeDir, new DefaultPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified path.
 /// <see cref="CompiledPluralRuleGenerator"/> will be used to generate a plural form rule.
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="parser"></param>
 public MoCompilingPluralLoader(string filePath, MoFileParser parser)
     : base(filePath, new CompiledPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoAstPluralLoader"/> class which will try to load a MO file
 /// that will be located in the localeDir using the domain name and catalog's culture info.
 /// <see cref="AstPluralRuleGenerator"/> will be used to generate a plural form rule.
 /// </summary>
 /// <param name="domain"></param>
 /// <param name="localeDir"></param>
 /// <param name="parser"></param>
 public MoAstPluralLoader(string domain, string localeDir, MoFileParser parser)
     : base(domain, localeDir, new AstPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified stream.
 /// <see cref="AstPluralRuleGenerator"/> will be used to generate a plural form rule.
 /// </summary>
 /// <param name="moStream"></param>
 /// <param name="parser"></param>
 public MoAstPluralLoader(Stream moStream, MoFileParser parser)
     : base(moStream, new AstPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified path.
 /// <see cref="AstPluralRuleGenerator"/> will be used to generate a plural form rule.
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="parser"></param>
 public MoAstPluralLoader(string filePath, MoFileParser parser)
     : base(filePath, new AstPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified stream.
 /// </summary>
 /// <param name="moStream"></param>
 /// <param name="parser"></param>
 public MoLoader(Stream moStream, MoFileParser parser)
     : this(moStream, new DefaultPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified path.
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="parser"></param>
 public MoLoader(string filePath, MoFileParser parser)
     : this(filePath, new DefaultPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// that will be located in the localeDir using the domain name and catalog's culture info.
 /// <see cref="CompiledPluralRuleGenerator"/> will be used to generate a plural form rule.
 /// </summary>
 /// <param name="domain"></param>
 /// <param name="localeDir"></param>
 /// <param name="parser"></param>
 public MoCompilingPluralLoader(string domain, string localeDir, MoFileParser parser)
     : base(domain, localeDir, new CompiledPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified stream.
 /// <see cref="AstPluralRuleGenerator"/> will be used to generate a plural form rule.
 /// </summary>
 /// <param name="moStream"></param>
 /// <param name="parser"></param>
 public MoAstPluralLoader(Stream moStream, MoFileParser parser)
     : base(moStream, new AstPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
 /// from the specified stream.
 /// <see cref="CompiledPluralRuleGenerator"/> will be used to generate a plural form rule.
 /// </summary>
 /// <param name="moStream"></param>
 /// <param name="parser"></param>
 public MoCompilingPluralLoader(Stream moStream, MoFileParser parser)
     : base(moStream, new CompiledPluralRuleGenerator(), parser)
 {
 }
Exemplo n.º 23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MoLoader"/> class which will try to load a MO file
        /// that will be located in the localeDir using the domain name and catalog's culture info.
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="localeDir"></param>
        /// <param name="pluralRuleGenerator"></param>
        /// <param name="parser"></param>
        public MoLoader(string domain, string localeDir, IPluralRuleGenerator pluralRuleGenerator, MoFileParser parser)
        {
            if (domain == null)
                throw new ArgumentNullException("domain");
            if (localeDir == null)
                throw new ArgumentNullException("localeDir");
            if (pluralRuleGenerator == null)
                throw new ArgumentNullException("pluralRuleGenerator");
            if (parser == null)
                throw new ArgumentNullException("parser");

            this._Domain = domain;
            this._LocaleDir = localeDir;
            this.PluralRuleGenerator = pluralRuleGenerator;
            this.Parser = parser;
        }