/// <summary> /// Constructor that searches for *.Localization.xml files in the language-specific /// sub-directory of the Resources sub-directory</summary> public EmbeddedResourceStringLocalizer() { // Get our current language and culture identifiers for the directory names. string language = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName; //"en" or "ja" string culture = Thread.CurrentThread.CurrentUICulture.Name; //"en-US" or "ja-JP" // Embedded resource namespaces can't contain certain characters and get renamed // automatically by the compiler. So, '-' got replaced by '_' while compiling. // https://msdn.microsoft.com/en-us/library/ms145952.aspx // Note that the Localization.xml files are not "strongly typed", so we can't use // StronglyTypedResourceBuilder.VerifyResourceName(). VerifyResourceName() would // change "as" (American Samoa) to "_as", but that name does not get changed by // the compiler. Since the only bad character we care about is '-', let's just fix it. culture = culture.Replace('-', '_'); // To speed things up, only check the GAC if this assembly has been installed in the GAC. // This allows us to skip mscorlib, etc. bool searchGAC = Assembly.GetExecutingAssembly().GlobalAssemblyCache; // Resources are named like "Some.Random.Namespace.Resources.ja.Another.Random.Name.Localization.xml". // Let's search for ".Resources.ja" to make sure we're locating the correct file. m_resourceDirectory1 = ".Resources." + language + "."; m_resourceDirectory2 = ".Resources." + culture + "."; foreach (Assembly assembly in AssemblyUtil.GetLoadedAssemblies()) { if (searchGAC || !assembly.GlobalAssemblyCache) { LoadEmeddedResources(assembly); } } // Subscribe to new assemblies AppDomain.CurrentDomain.AssemblyLoad += CurrentDomainOnAssemblyLoad; }