示例#1
0
    // ---------------- Dumping a GettextResourceSet ----------------

    private void Dump (GettextResourceSet catalog) {
      MethodInfo pluralMethod =
        catalog.GetType().GetMethod("GetMsgidPluralTable", Type.EmptyTypes);
      // Search for the header entry.
      {
        Object header_entry = catalog.GetObject("");
        // If there is no header entry, fake one.
        // FIXME: This is not needed; right after po_lex_charset_init set
        // the PO charset to UTF-8.
        if (header_entry == null)
          header_entry = "Content-Type: text/plain; charset=UTF-8\n";
        DumpMessage("", null, header_entry);
      }
      // Now the other messages.
      {
        Hashtable plural = null;
        if (pluralMethod != null)
          plural = pluralMethod.Invoke(catalog, new Object[0]) as Hashtable;
        foreach (String key in catalog.Keys)
          if (!"".Equals(key)) {
            Object value = catalog.GetObject(key);
            String key_plural =
              (plural != null && value is String[] ? plural[key] as String : null);
            DumpMessage(key, key_plural, value);
          }
      }
    }
示例#2
0
        // ---------------- Dumping a GettextResourceSet ----------------

        private void Dump(GettextResourceSet catalog)
        {
            MethodInfo pluralMethod =
                catalog.GetType().GetMethod("GetMsgidPluralTable", Type.EmptyTypes);
            // Search for the header entry.
            {
                Object header_entry = catalog.GetObject("");
                // If there is no header entry, fake one.
                // FIXME: This is not needed; right after po_lex_charset_init set
                // the PO charset to UTF-8.
                if (header_entry == null)
                {
                    header_entry = "Content-Type: text/plain; charset=UTF-8\n";
                }
                DumpMessage("", null, header_entry);
            }
            // Now the other messages.
            {
                Hashtable plural = null;
                if (pluralMethod != null)
                {
                    plural = pluralMethod.Invoke(catalog, new Object[0]) as Hashtable;
                }
                foreach (String key in catalog.Keys)
                {
                    if (!"".Equals(key))
                    {
                        Object value      = catalog.GetObject(key);
                        String key_plural =
                            (plural != null && value is String[] ? plural[key] as String : null);
                        DumpMessage(key, key_plural, value);
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Instantiates a resource set for a given culture.
        /// </summary>
        /// <exception cref="ArgumentException">
        ///   The expected type name is not valid.
        /// </exception>
        /// <exception cref="ReflectionTypeLoadException">
        ///   satelliteAssembly does not contain the expected type.
        /// </exception>
        /// <exception cref="NullReferenceException">
        ///   The type has no no-arguments constructor.
        /// </exception>
        private static GettextResourceSet InstantiateResourceSet(Assembly satelliteAssembly, String resourceName, CultureInfo culture)
        {
            string typeName = String.Format("GNU.Gettext.{0}", MakeResourceSetClassName(culture));
            // We expect a class with a culture dependent class name.
            Type type = satelliteAssembly.GetType(typeName);

            // We expect it has a no-argument constructor, and invoke it.
            ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);

            var instance = constructor.Invoke(null);
            GettextResourceSet result = instance as GettextResourceSet;

            return(result);
        }
示例#4
0
        public DumpResource(String baseDirectory, String resourceName, String cultureName)
        {
            // We are only interested in the messages belonging to the locale
            // itself, not in the inherited messages. Therefore we instantiate just
            // the GettextResourceSet, not a GettextResourceManager.
            Assembly satelliteAssembly =
                GetSatelliteAssembly(baseDirectory, resourceName, cultureName);
            GettextResourceSet catalog =
                InstantiateResourceSet(satelliteAssembly, resourceName, cultureName);
            BufferedStream stream = new BufferedStream(Console.OpenStandardOutput());

            Out = new StreamWriter(stream, new UTF8Encoding());
            Dump(catalog);
            Out.Close();
            stream.Close();
        }
示例#5
0
 /// <summary>
 /// Returns the array of <c>GettextResourceSet</c>s for a given culture,
 /// loading them if necessary, and maintaining the cache.
 /// </summary>
 private GettextResourceSet[] GetResourceSetsFor(CultureInfo culture)
 {
     //Console.WriteLine(">> GetResourceSetsFor "+culture);
     // Look up in the cache.
     GettextResourceSet[] result = (GettextResourceSet[])Loaded[culture];
     if (result == null)
     {
         lock (this) {
             // Look up again - maybe another thread has filled in the entry
             // while we slept waiting for the lock.
             result = (GettextResourceSet[])Loaded[culture];
             if (result == null)
             {
                 // Determine the GettextResourceSets for the given culture.
                 if (culture.Parent == null || culture.Equals(CultureInfo.InvariantCulture))
                 {
                     // Invariant culture.
                     result = EmptyResourceSetArray;
                 }
                 else
                 {
                     // Use a satellite assembly as primary GettextResourceSet, and
                     // the result for the parent culture as fallback.
                     GettextResourceSet[] parentResult = GetResourceSetsFor(culture.Parent);
                     Assembly             satelliteAssembly;
                     try {
                         satelliteAssembly = MySatelliteAssembly(culture);
                     } catch (FileNotFoundException e) {
                         satelliteAssembly = null;
                     }
                     if (satelliteAssembly != null)
                     {
                         GettextResourceSet satelliteResourceSet;
                         try {
                             satelliteResourceSet = InstantiateResourceSet(satelliteAssembly, BaseName, culture);
                         } catch (Exception e) {
                             Console.Error.WriteLine(e);
                             Console.Error.WriteLine(e.StackTrace);
                             satelliteResourceSet = null;
                         }
                         if (satelliteResourceSet != null)
                         {
                             result    = new GettextResourceSet[1 + parentResult.Length];
                             result[0] = satelliteResourceSet;
                             Array.Copy(parentResult, 0, result, 1, parentResult.Length);
                         }
                         else
                         {
                             result = parentResult;
                         }
                     }
                     else
                     {
                         result = parentResult;
                     }
                 }
                 // Put the result into the cache.
                 Loaded.Add(culture, result);
             }
         }
     }
     //Console.WriteLine("<< GetResourceSetsFor "+culture);
     return(result);
 }
示例#6
0
文件: intl.cs 项目: ryo/netbsd-src
 /// <summary>
 /// Returns the array of <c>GettextResourceSet</c>s for a given culture,
 /// loading them if necessary, and maintaining the cache.
 /// </summary>
 private GettextResourceSet[] GetResourceSetsFor(CultureInfo culture)
 {
     //Console.WriteLine(">> GetResourceSetsFor "+culture);
       // Look up in the cache.
       GettextResourceSet[] result = (GettextResourceSet[]) Loaded[culture];
       if (result == null) {
     lock(this) {
       // Look up again - maybe another thread has filled in the entry
       // while we slept waiting for the lock.
       result = (GettextResourceSet[]) Loaded[culture];
       if (result == null) {
     // Determine the GettextResourceSets for the given culture.
     if (culture.Parent == null || culture.Equals(CultureInfo.InvariantCulture))
       // Invariant culture.
       result = EmptyResourceSetArray;
     else {
       // Use a satellite assembly as primary GettextResourceSet, and
       // the result for the parent culture as fallback.
       GettextResourceSet[] parentResult = GetResourceSetsFor(culture.Parent);
       Assembly satelliteAssembly;
       try {
         satelliteAssembly = MySatelliteAssembly(culture);
       } catch (FileNotFoundException e) {
         satelliteAssembly = null;
       }
       if (satelliteAssembly != null) {
         GettextResourceSet satelliteResourceSet;
         try {
           satelliteResourceSet = InstantiateResourceSet(satelliteAssembly, BaseName, culture);
         } catch (Exception e) {
           Console.Error.WriteLine(e);
           Console.Error.WriteLine(e.StackTrace);
           satelliteResourceSet = null;
         }
         if (satelliteResourceSet != null) {
           result = new GettextResourceSet[1+parentResult.Length];
           result[0] = satelliteResourceSet;
           Array.Copy(parentResult, 0, result, 1, parentResult.Length);
         } else
           result = parentResult;
       } else
         result = parentResult;
     }
     // Put the result into the cache.
     Loaded.Add(culture, result);
       }
     }
       }
       //Console.WriteLine("<< GetResourceSetsFor "+culture);
       return result;
 }