/// <summary> /// Checks whether a localized file for the given resource type is /// available. Caches the result for the current culture as the /// operation relies on expensive reflections. /// </summary> /// <param name="type">The type to check for a localized copy.</param> /// <returns>True if a localized version of the associated resource file exists.</returns> private static bool IsResourceTypeLocalized(L10nResourceType type) { int index = (int)type; // We cache the result to improve the overall performance. if (!_isLocalized[index].HasValue) { // For the default language all strings should be available if (IsDefaultLanguage) { _isLocalized[index] = true; return true; } // Try to load the satelite assembly for the current culture and // check if a resource file for the current culture is embedded. Assembly satellite = null; if (_currentAssembly.TryGetSatelliteAssembly(_uiCulture, out satellite)) { string resourceBaseName = _l10nResources[index].BaseName; _isLocalized[index] = satellite.ContainsResource(resourceBaseName, _uiCulture); } else { _isLocalized[index] = false; } } return _isLocalized[index].Value; }
/// <summary> /// Tries to retrieve a translated string with respect the currently active /// application language. /// </summary> /// <param name="key">The unique identifier of the string to lookup.</param> /// <param name="type">The resource file to use for the lookup process.</param> /// <returns>The translated string, or null if no tranlation available.</returns> public static string LookUpLocalizedString(string key, L10nResourceType type) { // Handle: No key value given if (string.IsNullOrWhiteSpace(key)) return string.Empty; ResourceManager resx = _l10nResources[(int)type]; string value = string.Empty; if (resx != null) value = resx.GetString(key, _uiCulture); return !string.IsNullOrWhiteSpace(value) ? value : null; }