Beispiel #1
0
 private static object[] GetArgsWithToken(LookupToken token, object[] args)
 {
     object[] newArgs = new object[args.Length + 1];
     newArgs[0] = token;
     Array.Copy(args, 0, newArgs, 1, args.Length);
     return newArgs;
 }
Beispiel #2
0
 public string GetLocalizedString(LocalizedStrings key, params object[] args)
 {
     Debug.WriteLine("Looking up localized string: " + key);
     LookupToken token = new LookupToken(this);
     args = GetArgsWithToken(token, args);
     return GetLocalizedString(token, key.ToString(), args);
 }
Beispiel #3
0
 private static object[] GetArgsWithToken(LookupToken token, object[] args)
 {
     object[] newArgs = new object[args.Length + 1];
     newArgs[0] = token;
     Array.Copy(args, 0, newArgs, 1, args.Length);
     return(newArgs);
 }
Beispiel #4
0
        public string GetLocalizedString(LocalizedStrings key, params object[] args)
        {
            Debug.WriteLine("Looking up localized string: " + key);
            LookupToken token = new LookupToken(this);

            args = GetArgsWithToken(token, args);
            return(GetLocalizedString(token, key.ToString(), args));
        }
Beispiel #5
0
        public string Format(string format, object arg, IFormatProvider formatProvider)
        {
            LookupToken lookupToken = arg as LookupToken;

            // Linking to another localized string
            if (lookupToken != null)
            {
                // Using {0} directly is prohibited
                if (format == null)
                {
                    throw new FormatException("Cannot use {0} directly; you must specify another string");
                }
                try
                {
                    string str = lookupToken.GetLocalizedString(format);
                    Debug.WriteLine("Linking to localized string: " + format);
                    return(str);
                }
                catch (KeyNotFoundException ex)
                {
                    throw new FormatException("Linking to undefined string: " + format, ex);
                }
            }

            // Using a switch table
            if (format == null)
            {
                return(arg.ToString());
            }
            SwitchTable table;

            if (!_switchTables.TryGetValue(format, out table))
            {
                throw new FormatException("Attempting to use undefined switch table: " + format);
            }
            if (_seenSwitchTableNames.Add(format))
            {
                throw new FormatException("Recursive switch table definition: " + format);
            }
            Debug.WriteLine(string.Format("Looking up value in switch table: {0} > {1}", format, arg));
            return(string.Format(this, table[arg.ToString()], _args));
        }
Beispiel #6
0
 internal string GetLocalizedString(LookupToken token, string key, params object[] args)
 {
     // args[0] and token must refer to the same object
     token.MarkString(key);
     return _strings[key].Format(args);
 }
Beispiel #7
0
 internal string GetLocalizedString(LookupToken token, string key, params object[] args)
 {
     // args[0] and token must refer to the same object
     token.MarkString(key);
     return(_strings[key].Format(args));
 }