public static string GetUIString(string key) { string uiString; LocExtension locExtension = new LocExtension(String.Format("DriversGalaxy.Infrastructure:Resources:{0}", key)); locExtension.ResolveLocalizedValue(out uiString); return uiString; }
public static string GetUIString(string key) { string uiString; LocExtension locExtension = new LocExtension(String.Format("FreeDriverScout:Resources:{0}", key)); locExtension.ResolveLocalizedValue(out uiString); return uiString; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (parameter == null) return values; var bindingParams = (object[])values.Clone(); // Remove the {DependancyProperty.UnsetValue} from unbound datasources. for (var i = 0; i < bindingParams.Length; i++) { if (bindingParams[i] != null && bindingParams[i] == DependencyProperty.UnsetValue) { bindingParams[i] = null; } } var keyStr = (string)parameter; #pragma warning disable 618 // It needs to identify the Assembly and Dictionary, as the Converter doesn't know squat about what is defined on the Window. var ext = new LocExtension(keyStr) { Assembly = "SEToolbox", Dict = "Resources" }; #pragma warning restore 618 string localizedValue; return ext.ResolveLocalizedValue(out localizedValue) ? string.Format(localizedValue, bindingParams) : null; }
/// <summary> /// Get localized string from resource dictionary /// </summary> /// <param name="key"></param> /// <returns></returns> public string GetLocalizedString(string key) { string uiString; LocExtension locExtension = new LocExtension(key); locExtension.ResolveLocalizedValue(out uiString); return uiString; }
public string Localize(string key) { string str; LocExtension loc = new LocExtension("LunchViewer:Strings:" + key); loc.ResolveLocalizedValue(out str); return str; }
public static T GetLocalizedValue <T>(string key, string resources = "Resources", string assembly = null) { if (assembly == null) { assembly = Assembly.GetCallingAssembly().GetName().Name; } return(LocExtension.GetLocalizedValue <T>(assembly + ":" + resources + ":" + key)); }
public static string GetUIString(string key) { string uiString; LocExtension locExtension = new LocExtension(String.Format("DriversGalaxy:Resources:{0}", key)); locExtension.ResolveLocalizedValue(out uiString); return(uiString); }
/// <summary> /// Get localized string from resource dictionary /// </summary> /// <param name="key"></param> /// <returns></returns> public string GetLocalizedString(string key) { string uiString; LocExtension locExtension = new LocExtension(key); locExtension.ResolveLocalizedValue(out uiString); return(uiString); }
/// <summary> /// assemblyName + ":" + resourceName + ":" + key /// </summary> /// <typeparam name="T"></typeparam> /// <param name="resourceKey"></param> /// <returns></returns> static public T Get <T>(string resourceKey) { T uiString; var locExtension = new LocExtension(resourceKey); locExtension.ResolveLocalizedValue <T>(out uiString); return(uiString); }
static public T Get <T>(string assemblyName, string resourceName, string key) { T uiString; var locExtension = new LocExtension(assemblyName + ":" + resourceName + ":" + key); locExtension.ResolveLocalizedValue <T>(out uiString); return(uiString); }
public static string GetUIString(string key) { string uiString; LocExtension locExtension = new LocExtension("Software:Strings:" + key); locExtension.ResolveLocalizedValue(out uiString); return(uiString); }
private void UpdateStrings() { string str; LocExtension loc = new LocExtension("WpfLocalizationTest:Strings:code_property"); loc.ResolveLocalizedValue(out str); Text = str; }
public static string Localize(this string key) { string localized; var locExtension = new LocExtension(key); locExtension.ResolveLocalizedValue(out localized); return localized; }
public static string GetUIString(string key) { string uiString; LocExtension locExtension = new LocExtension(String.Format("FreeDriverScout.Infrastructure:Resources:{0}", key)); locExtension.ResolveLocalizedValue(out uiString); return(uiString); }
public string Localize(string key) { string str; LocExtension loc = new LocExtension("LunchViewer:Strings:" + key); loc.ResolveLocalizedValue(out str); return(str); }
public string Localize(string key, string culture) { var culture_info = CultureInfo.CreateSpecificCulture(culture); string str; LocExtension loc = new LocExtension("LunchViewer:Strings:" + key); loc.ResolveLocalizedValue(out str, culture_info); return str; }
public string Localize(string key, string culture) { var culture_info = CultureInfo.CreateSpecificCulture(culture); string str; LocExtension loc = new LocExtension("LunchViewer:Strings:" + key); loc.ResolveLocalizedValue(out str, culture_info); return(str); }
public static string L(string key) { var text = LocExtension.GetLocalizedValue <string>(key); if (string.IsNullOrEmpty(text)) { return(key); } return(text); }
static IOfficeModule CreateHomePage() { return(new OfficeModule { Title = LocExtension.GetLocalizedValue <string>("CoreModule_Title"), Description = LocExtension.GetLocalizedValue <string>("CoreModule_Description"), ToolTip = LocExtension.GetLocalizedValue <string>("CoreModule_Tooltip"), TargetUri = new Uri(CoreViews.ModulesView, UriKind.Relative), }); }
public static string StringText(string key) { string s = LocExtension.GetLocalizedValue <string>("Cognitivo:local:" + key); if (s == null) { s = key; } return(s); }
private void Localize() { foreach (var Column in Columns) { string str = LocExtension.GetLocalizedValue <string>("Cognitivo:local:" + Column.Header.ToString()); if (!string.IsNullOrEmpty(str)) { Column.Header = str; } } }
/// <summary> /// 多言語対応のためにResourcesから文言を抜き出すためのメソッド /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <returns></returns> public static T GetLocalizedValue <T>(string key) { //メインアプリのリソースを使う時 //var temp = Assembly.GetCallingAssembly().GetName().Name + ":Resources:" + key; //任意のプロジェクトのリソースを固定して使う時は直接書けばいい var temp = "CommonModels:Resources:" + key; var ret = LocExtension.GetLocalizedValue <T>(temp); return(ret); }
/// <summary> /// Cancels changes made to Entity asking the user to approve this method before continuing. /// </summary> public void CancelChanges_withQuestion() { string str = LocExtension.GetLocalizedValue <string>("Cognitivo:local:" + "Question_Cancel"); if (MessageBox.Show(str, "Cognitivo ERP", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { CancelChanges(); } }
public string GetLocalizedString(string key, string assembly, string dictionary) { string value; string prefix = string.Format("{0}:{1}:", assembly, dictionary); LocExtension locExtension = new LocExtension(prefix + key); locExtension.ResolveLocalizedValue(out value); return(value); }
/// <summary> /// 获取本地化的字符串 /// </summary> /// <param name="key">欲获取资源的Key</param> /// <param name="resourceFileName">资源文件名称</param> /// <param name="addSpaceAfter"></param> /// <returns></returns> public static string GetLocalizedString(string key, string resourceFileName) { var localizedString = String.Empty; // Build up the fully-qualified name of the key var assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; var fullKey = assemblyName + ":" + resourceFileName + ":" + key; var locExtension = new LocExtension(fullKey); locExtension.ResolveLocalizedValue(out localizedString); return(localizedString); }
/// <summary> /// Get localized string from resource dictionary /// </summary> /// <param name="key"></param> /// <returns></returns> public string GetLocalizedString(string key) { LocExtension locExtension = new LocExtension(key); if (locExtension.ResolveLocalizedValue(out string uiString)) { return(uiString); } return(key); //var assemblyProp = ResxLocalizationProvider.Instance.FallbackAssembly; //var uiString = LocExtension.GetLocalizedValue<string>(assemblyProp + ":Resources:" + key); //return uiString; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int _value = (int)value; if ((int)Status.Documents_General.Approved == _value) { return(LocExtension.GetLocalizedValue <string>("Cognitivo:local:" + "Approve"));; } else { return(LocExtension.GetLocalizedValue <string>("Cognitivo:local:" + "Pending"));; } }
private void Window_StateChanged(object sender, EventArgs e) { if (this.WindowState == WindowState.Minimized) { this.Hide(); if (!this.notification_showed) { this.notification_showed = true; var title = LocExtension.GetLocalizedValue <string>("BililiveRecorder.WPF:Strings:TaskbarIconControl_Title"); var body = LocExtension.GetLocalizedValue <string>("BililiveRecorder.WPF:Strings:TaskbarIconControl_MinimizedNotification"); this.ShowBalloonTipCallback?.Invoke(title, body, BalloonIcon.Info); } } }
public BindingLoc(string path) : base() { Converter = new MultiConverter <string>(data => { if (data.Values?.Length > 0) { try { var culture = LocalizeDictionary.Instance.SpecificCulture; var key = data.Values[0].ToString(); var value = LocExtension.GetLocalizedValue(data.TargetType, key, culture, null); if (value == null) { var missingKeyEventResult = LocalizeDictionary.Instance.OnNewMissingKeyEvent(this, key); if ( LocalizeDictionary.Instance.OutputMissingKeys && !string.IsNullOrEmpty(key) && (data.TargetType == typeof(string) || data.TargetType == typeof(object)) ) { value = missingKeyEventResult.MissingKeyResult != null ? missingKeyEventResult.MissingKeyResult : "Key: " + key; } } var result = $"{Prefix}{value}{Suffix}"; result = Format?.F(result) ?? result; result = Lower ? result.ToLower() : Upper ? result.ToUpper() : result; return(result); } catch { } } return(null); }); KeyBinding = new Binding(path); Bindings.Add(KeyBinding); Bindings.Add(new Markup.Options() { Path = new PropertyPath("Language") }); }
static public bool BindTo(DependencyObject objectToBind, DependencyProperty propertyToBind, string resourceKey) { if (resourceKey == null) { return(false); } if (resourceKey.Count(c => c.Equals(':')) != 2) { Log.Info("localized resource key: " + resourceKey + " for object:" + objectToBind.ToString() + "; propety:" + propertyToBind.ToString() + " is not parsed, it is used directly." + "(Valid key format is assemblyName:resourceFileName:resourceKeyName)"); objectToBind.SetValue(propertyToBind, resourceKey); return(false); } objectToBind.ClearValue(propertyToBind); var loc = new LocExtension(resourceKey); return(loc.SetBinding(objectToBind, propertyToBind)); }
private void Regedit(object sender, RoutedEventArgs e) { try { // Directory Registry.ClassesRoot.DeleteSubKeyTree(@"Directory\shell\sd_pck", false); Registry.ClassesRoot.DeleteSubKeyTree(".pck", false); Registry.ClassesRoot.DeleteSubKeyTree(".cup", false); Registry.ClassesRoot.DeleteSubKeyTree("sdPck", false); using (var key = Registry.ClassesRoot.CreateSubKey(@"Directory\shell").CreateSubKey("sd_pck", RegistryKeyPermissionCheck.ReadWriteSubTree)) { key.SetValue("Icon", $"{System.Reflection.Assembly.GetExecutingAssembly().Location},0"); key.SetValue("MUIVerb", LocExtension.GetLocalizedValue <string>("ContextCompress"), RegistryValueKind.String); using (var key1 = key.CreateSubKey("command")) { key1.SetValue(string.Empty, $"{System.Reflection.Assembly.GetExecutingAssembly().Location} \"%1\"", RegistryValueKind.ExpandString); } } // PCK using (var key = Registry.ClassesRoot.CreateSubKey(".pck")) { key.SetValue(string.Empty, $"sdPck", RegistryValueKind.String); } // CUP using (var key = Registry.ClassesRoot.CreateSubKey(".cup")) { key.SetValue(string.Empty, $"sdPck", RegistryValueKind.String); } using (var key = Registry.ClassesRoot.CreateSubKey("sdPck")) { key.SetValue(string.Empty, "Archive manager for Angelica Engine by Wanmei"); using (var key1 = key.CreateSubKey("DefaultIcon")) { key1.SetValue(string.Empty, $"{System.Reflection.Assembly.GetExecutingAssembly().Location},0"); } key.CreateSubKey(@"Shell\Open\Command").SetValue(string.Empty, $"{System.Reflection.Assembly.GetExecutingAssembly().Location} \"%1\""); } } catch { MessageBox.Show("Для изменения реестра нужно запустить программу от имени администратора"); } }
/// <summary> /// Programmatic method for retrieving a localized string via key from a resource file. /// </summary> /// <param name="key">The key for the string.</param> /// <param name="resourceFileName">(Optional) The name of the Resource file. Default: Strings.</param> /// <param name="addSpaceAfter">A System.Boolean indicating if a whitespace character should be appended to the end of the localized string.</param> /// <returns></returns> public static string GetLocalizedString(string key, string resourceFileName = "Strings", bool addSpaceAfter = false) { var localizedString = String.Empty; // Build up the fully-qualified name of the key var assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; var fullKey = assemblyName + ":" + resourceFileName + ":" + key; var locExtension = new LocExtension(fullKey); locExtension.ResolveLocalizedValue(out localizedString); // Add a space to the end, if requested if (addSpaceAfter) { localizedString += " "; } return(localizedString); }
/// <inheritdoc/> public string GetLocalisedString( string key) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } var lookupValue = _resourceFiles .OrderBy(pair => pair.Value) .Select( pair => { var lookup = $"{pair.Key}:{key}"; return(LocExtension.GetLocalizedValue <string>(lookup)); }) .FirstOrDefault(value => !string.IsNullOrWhiteSpace(value)); return(lookupValue ?? throw new KeyNotFoundException($"Cannot find key {key} in resource dictionary")); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return(string.Empty); } var sb = new StringBuilder(); var svalue = value.ToString(); if (parameter != null) { var sparam = parameter.ToString(); if (!string.IsNullOrWhiteSpace(sparam)) { svalue = $"{svalue}.{sparam}"; } } var res = LocExtension.GetLocalizedValue <string>(svalue, Settings.Instance.Localization.Culture); return(res); }
public static string GetLocalizedString(string key, bool addSpaceAfter = false, string resourceFileName = "MarkdownPadStrings") { string text = string.Empty; string name = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; string key2 = string.Concat(new string[] { name, ":", resourceFileName, ":", key }); LocExtension locExtension = new LocExtension(key2); locExtension.ResolveLocalizedValue <string>(out text); if (addSpaceAfter) { text += " "; } return(text); }
public MainWindow() { this.DataContext = new MyViewModel(); InitializeComponent(); string localisedValue = string.Empty; //ILocalizationProvider cvsProvider = new CSVLocalizationProvider() { FileName = "Example", HasHeader = true }; //LocalizeDictionary.Instance.DefaultProvider = cvsProvider; //LocExtension locExtension = new LocExtension(); //locExtension.Key = "TestText"; //locExtension.ResolveLocalizedValue<string>(out localisedValue, new CultureInfo("de")); //localisedValue = (string)LocalizeDictionary.Instance.GetLocalizedObject("TestText", null, new CultureInfo("de"), cvsProvider); localisedValue = LocExtension.GetLocalizedValue <string>("AssemblyTestResourceLib:Strings:TestText"); Console.WriteLine(localisedValue); }
private static ImageSource GetImage(string key) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } var keyinternal = GetRightKey(key, ".png"); object bitmap; var res = new LocExtension(keyinternal).ResolveLocalizedValue(out bitmap); if (res) { if (bitmap is Bitmap) { return(((Bitmap)bitmap).GetBitmapImage()); } throw new DeveloperException("Bad Image format."); } throw new DeveloperException("Can't find resource by the key '{0}'.", keyinternal); }
/// <summary> /// Creates a new enum localizer. /// </summary> public LocProxy() { ext = new LocExtension(); ext.SetBinding(this, GetType().GetProperty("Result")); }
/// <summary> /// Evaluates a property using the StringParser. Equivalent to StringParser.Parse("${" + propertyName + "}"); /// </summary> public static string GetValue(string propertyName, params StringTagPair[] customTags) { if(propertyName == null) throw new ArgumentNullException("propertyName"); if(propertyName == "$") return "$"; if(customTags != null){ foreach(StringTagPair pair in customTags){ if(propertyName.Equals(pair.Tag, StringComparison.OrdinalIgnoreCase)) return pair.Value; } } int k = propertyName.IndexOf(':'); if(k <= 0){ // it's property without prefix if(propertyName.Equals("DATE", StringComparison.OrdinalIgnoreCase)) return DateTime.Today.ToShortDateString(); if(propertyName.Equals("TIME", StringComparison.OrdinalIgnoreCase)) return DateTime.Now.ToShortTimeString(); if(propertyName.Equals("ProductName", StringComparison.OrdinalIgnoreCase)) return IoC.Get<IMessageService>().ProductName; if(propertyName.Equals("GUID", StringComparison.OrdinalIgnoreCase)) return Guid.NewGuid().ToString().ToUpperInvariant(); if(propertyName.Equals("USER", StringComparison.OrdinalIgnoreCase)) return Environment.UserName; if(propertyName.Equals("Version", StringComparison.OrdinalIgnoreCase)) return "1.00"; if(propertyName.Equals("CONFIGDIRECTORY", StringComparison.OrdinalIgnoreCase)) return IoC.Get<IPropertyService>().ConfigDirectory; foreach(IStringTagProvider provider in string_tag_providers){ string result = provider.ProvideString(propertyName, customTags); if(result != null) return result; } return null; }else{ // it's a prefixed property // res: properties are quite common, so optimize by testing for them first // before allocaing the prefix/propertyName strings // All other prefixed properties {prefix:Key} shoulg get handled in the switch below. if(propertyName.StartsWith("res:", StringComparison.OrdinalIgnoreCase)){ string str_resource; var loc_extension = new LocExtension(ValidateIdentifier(propertyName.Substring(4))); if(!loc_extension.ResolveLocalizedValue(out str_resource)) return null; return Parse(str_resource, customTags); } string prefix = propertyName.Substring(0, k); propertyName = propertyName.Substring(k + 1); switch(prefix.ToUpperInvariant()){ case "SDKTOOLPATH": return FileUtility.GetSdkPath(propertyName); case "ADDINPATH": foreach(var add_in in IoC.Get<IAddInTree>().AddIns){ if(add_in.Manifest.Identities.ContainsKey(propertyName)) return System.IO.Path.GetDirectoryName(add_in.FileName); } return null; case "DATE": try{ return DateTime.Now.ToString(propertyName, CultureInfo.CurrentCulture); }catch(Exception ex){ return ex.Message; } case "ENV": return Environment.GetEnvironmentVariable(propertyName); case "PROPERTY": return GetProperty(propertyName); default: IStringTagProvider provider; if(prefixed_string_tag_providers.TryGetValue(prefix, out provider)) return provider.ProvideString(propertyName, customTags); else return null; } } }