Ejemplo n.º 1
0
        // Note: the output of this function is currently treated as mutable.
        public Dictionary <Locale, string> GetNamesByLocale(int expectedSegments)
        {
            TODO.MoreExtensibleFormOfParsingAnnotations();

            Dictionary <Locale, string> output = new Dictionary <Locale, string>();

            if (annotations != null && this.annotations.ContainsKey("localized"))
            {
                foreach (Annotation annotation in this.annotations["localized"])
                {
                    if (annotation.Args.Length != 2 ||
                        !(annotation.Args[0] is StringConstant) ||
                        !(annotation.Args[1] is StringConstant))
                    {
                        throw this.parser.GenerateParseError(
                                  ErrorMessages.LOCALIZED_ANNOTATION_ARGUMENT_MUST_HAVE_2_STRINGS,
                                  annotation.FirstToken);
                    }

                    string localeId     = ((StringConstant)annotation.Args[0]).Value;
                    string name         = ((StringConstant)annotation.Args[1]).Value;
                    int    segmentCount = name.Contains('.') ? name.Split('.').Length : 1;
                    if (segmentCount != expectedSegments)
                    {
                        throw this.parser.GenerateParseError(
                                  ErrorMessages.LOCALIZED_ANNOTATION_MUST_CONTAIN_SAME_NUMBER_DOTTED_SEGMENTS,
                                  annotation.FirstToken);
                    }
                    Locale locale = Locale.Get(localeId);
                    output[locale] = name;
                }
            }
            return(output);
        }
Ejemplo n.º 2
0
        // Note: the output of this function is currently treated as mutable.
        public Dictionary <Locale, string> GetNamesByLocale(int expectedSegments)
        {
            TODO.MoreExtensibleFormOfParsingAnnotations();

            Dictionary <Locale, string> output = new Dictionary <Locale, string>();

            if (annotations != null && this.annotations.ContainsKey("localized"))
            {
                foreach (Annotation annotation in this.annotations["localized"])
                {
                    if (annotation.Args.Length != 2 ||
                        !(annotation.Args[0] is StringConstant) ||
                        !(annotation.Args[1] is StringConstant))
                    {
                        throw new ParserException(
                                  annotation.FirstToken,
                                  "@localized argument must have 2 constant string arguments.");
                    }

                    string localeId     = ((StringConstant)annotation.Args[0]).Value;
                    string name         = ((StringConstant)annotation.Args[1]).Value;
                    int    segmentCount = name.Contains('.') ? name.Split('.').Length : 1;
                    if (segmentCount != expectedSegments)
                    {
                        throw new ParserException(
                                  annotation.Args[1].FirstToken,
                                  "@localized name must contain the same number of dotted segments as the original definition.");
                    }
                    Locale locale = Locale.Get(localeId);
                    output[locale] = name;
                }
            }
            return(output);
        }