Stetic.PropertyDescriptor.SetTranslated C# (CSharp) Method

SetTranslated() public method

public SetTranslated ( object obj, bool translated ) : void
obj object
translated bool
return void
        public virtual void SetTranslated(object obj, bool translated)
        {
            ObjectWrapper wrapper = ObjectWrapper.Lookup (obj);
            if (wrapper == null) return;

            if (wrapper.translationInfo == null)
                wrapper.translationInfo = new Hashtable ();

            TranslationInfo info = (TranslationInfo)wrapper.translationInfo[obj];
            if (info == null) {
                info = new TranslationInfo ();
                wrapper.translationInfo[obj] = info;
            }

            if (translated)
                info.Translated = true;
            else
                info.Translated = false;
            // We leave the old Context and Comment around, so that if
            // you toggle Translated off and then back on, the old info
            // is still there.
        }

Usage Example

Example #1
0
        public static void ReadProperty(ClassDescriptor klass, ObjectWrapper wrapper, object wrapped, XmlElement prop_node)
        {
            string             name = prop_node.GetAttribute("name");
            PropertyDescriptor prop = klass [name] as PropertyDescriptor;

            if (prop == null || !prop.CanWrite)
            {
                return;
            }

            string strval = prop_node.InnerText;

            // Skip translation context
            if (prop_node.GetAttribute("context") == "yes" && strval.IndexOf('|') != -1)
            {
                strval = strval.Substring(strval.IndexOf('|') + 1);
            }

            object value = prop.StringToValue(strval);

            prop.SetValue(wrapped, value);

            if (prop.Translatable)
            {
                if (prop_node.GetAttribute("translatable") != "yes")
                {
                    prop.SetTranslated(wrapped, false);
                }
                else
                {
                    prop.SetTranslated(wrapped, true);
                    if (prop_node.GetAttribute("context") == "yes")
                    {
                        strval = prop_node.InnerText;
                        int bar = strval.IndexOf('|');
                        if (bar != -1)
                        {
                            prop.SetTranslationContext(wrapped, strval.Substring(0, bar));
                        }
                    }

                    if (prop_node.HasAttribute("comments"))
                    {
                        prop.SetTranslationComment(wrapped, prop_node.GetAttribute("comments"));
                    }
                }
            }
        }