public static void AddTranslationItem(string category, object obj, string propName, ITranslation translation)
        {
            var property = obj?.GetType().GetProperty(propName, _propertyFlags);

            if (property?.GetValue(obj, null) is string value && AllowTranslateProperty(value))
            {
                translation.AddTranslationItem(category, propName, "Text", value);
            }
        }
 public static void AddTranslationItemsFromList(string category, ITranslation translation, IEnumerable<Tuple<string, object>> items)
 {
     Action<string, object, PropertyInfo> action = delegate(string item, object itemObj, PropertyInfo propertyInfo)
     {
         var value = (string)propertyInfo.GetValue(itemObj, null);
         if (AllowTranslateProperty(value))
         {
             translation.AddTranslationItem(category, item, propertyInfo.Name, value);
         }
     };
     ForEachItem(items, action);
 }
        public static void AddTranslationItem(string category, object obj, string propName, ITranslation translation)
        {
            var propertyInfo = obj?.GetType().GetProperty(
                propName,
                BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static |
                BindingFlags.NonPublic | BindingFlags.SetProperty);

            if (propertyInfo?.GetValue(obj, null) is string value && AllowTranslateProperty(value))
            {
                translation.AddTranslationItem(category, propName, "Text", value);
            }
        }
        public static void AddTranslationItemsFromList(string category, ITranslation translation, IEnumerable <Tuple <string, object> > items)
        {
            foreach (var item in items)
            {
                var itemName = item.Item1;
                var itemObj  = item.Item2;
                foreach (var property in GetItemPropertiesEnumerator(item))
                {
                    var value = property.GetValue(itemObj, null);
                    if (value == null)
                    {
                        continue;
                    }

                    var valueStr = value as string;
                    if (valueStr != null)
                    {
                        if (AllowTranslateProperty(valueStr))
                        {
                            translation.AddTranslationItem(category, itemName, property.Name, valueStr);
                        }

                        continue;
                    }

                    var listItems = value as IList;
                    if (listItems != null)
                    {
                        for (int index = 0; index < listItems.Count; index++)
                        {
                            var listItem = listItems[index] as string;
                            if (AllowTranslateProperty(listItem))
                            {
                                translation.AddTranslationItem(category, itemName, "Item" + index, listItem);
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        public static void AddTranslationItemsFromList(string category, ITranslation translation, IEnumerable <Tuple <string, object> > items)
        {
            Action <string, object, PropertyInfo> action = delegate(string item, object itemObj, PropertyInfo propertyInfo)
            {
                var value = (string)propertyInfo.GetValue(itemObj, null);
                if (AllowTranslateProperty(value))
                {
                    translation.AddTranslationItem(category, item, propertyInfo.Name, value);
                }
            };

            ForEachItem(items, action);
        }
        public static void AddTranslationItem(string category, object obj, string propName, ITranslation translation)
        {
            if (obj == null)
                return;

            var propertyInfo = obj.GetType().GetProperty(propName,
                BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static |
                BindingFlags.NonPublic | BindingFlags.SetProperty);
            if (propertyInfo == null)
            {
                return;
            }
            var value = propertyInfo.GetValue(obj, null) as string;
            if (value != null && AllowTranslateProperty(value))
            {
                translation.AddTranslationItem(category, propName, "Text", value);
            }
        }
Exemple #7
0
        public static void AddTranslationItem(string category, object obj, string propName, ITranslation translation)
        {
            if (obj == null)
            {
                return;
            }

            var propertyInfo = obj.GetType().GetProperty(propName,
                                                         BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static |
                                                         BindingFlags.NonPublic | BindingFlags.SetProperty);

            if (propertyInfo == null)
            {
                return;
            }
            var value = propertyInfo.GetValue(obj, null) as string;

            if (value != null && AllowTranslateProperty(value))
            {
                translation.AddTranslationItem(category, propName, "Text", value);
            }
        }
        public static void AddTranslationItemsFromList(string category, ITranslation translation, IEnumerable<Tuple<string, object>> items)
        {
            foreach (var item in items)
            {
                var itemName = item.Item1;
                var itemObj = item.Item2;
                foreach (var property in GetItemPropertiesEnumerator(item))
                {
                    var value = property.GetValue(itemObj, null);
                    if (value == null)
                        continue;
                    var valueStr = value as string;
                    if (valueStr != null)
                    {
                        if (AllowTranslateProperty(valueStr))
                        {
                            translation.AddTranslationItem(category, itemName, property.Name, valueStr);
                        }
                        continue;
                    }

                    var listItems = value as IList;
                    if (listItems != null)
                    {
                        for (int index = 0; index < listItems.Count; index++)
                        {
                            var listItem = listItems[index] as string;
                            if (AllowTranslateProperty(listItem))
                            {
                                translation.AddTranslationItem(category, itemName, "Item" + index, listItem);
                            }
                        }
                    }
                }
            }
        }