Beispiel #1
0
        private static bool TryHandleLocalizationBinding(BindingExpression bindingExpression, PropertyInfo targetProperty, IValueConverter converter)
        {
            if (bindingExpression.Source.StartsWith("@"))
            {
                string locName  = bindingExpression.Source.Substring(1);
                string locValue = PortableLocalizedResources.GetString(locName);

                SetTargetProperty(locValue, bindingExpression.View, targetProperty, converter, bindingExpression.ConverterParameter);

                return(true);
            }

            return(false);
        }
Beispiel #2
0
        private static bool LocalizeProperty <T>(View view, Func <T, string> getOriginalText, Action <T, string> assignLocalizedText)
            where T : class
        {
            T castedView = view as T;

            if (castedView == null)
            {
                return(false);
            }

            string originalText = getOriginalText(castedView);

            if (originalText != null && originalText.Length > 2 && originalText[0] == '{' && originalText[originalText.Length - 1] == '}')
            {
                assignLocalizedText(castedView, PortableLocalizedResources.GetString(originalText.Substring(1, originalText.Length - 2)));
            }

            // Returning true indicates that the view was of the specified type, so that the caller can stop checking different types
            return(true);
        }
        public static string GetString(string id)
        {
            if (LocalizationExtension.Current != null)
            {
                return(LocalizationExtension.Current.GetString(id));
            }

            if (_resourceManager == null)
            {
                //_resourceManager = Strings.Resources.ResourceManager;
                _resourceManager = new ResourceManager("PowerPlannerAppDataLibrary.Strings.Resources", typeof(PowerPlannerResources).GetTypeInfo().Assembly);
            }

            if (_cultureInfo == null)
            {
                _cultureInfo = PortableLocalizedResources.GetCurrentCulture();
            }

            return(_resourceManager.GetString(id, _cultureInfo));
        }
        public static string GetCapitalizedString(string id)
        {
            string str = GetString(id);

            if (str.Length > 0)
            {
                if (_cultureInfo == null)
                {
                    _cultureInfo = PortableLocalizedResources.GetCurrentCulture();
                }

                if (_cultureInfo.TwoLetterISOLanguageName == "ar")
                {
                    return(str.Substring(0, str.Length - 1) + char.ToUpper(str[str.Length - 1]));
                }

                return(char.ToUpper(str[0]) + str.Substring(1));
            }

            return(str);
        }