Ejemplo n.º 1
0
        public static LanguageDataObject GetTranslation(string language, ITranslatableObject obj)
        {
            LanguageDataObject translation;

            TryGetTranslation(out translation, language, obj);
            return(translation);
        }
Ejemplo n.º 2
0
        public static LanguageDataObject GetTranslation(GameClient client, ITranslatableObject obj)
        {
            LanguageDataObject translation;

            TryGetTranslation(out translation, client, obj);
            return(translation);
        }
        /// <summary>
        /// Reads any translations stored in the annotations of the current instance of an ITranslatableObject,
        /// and applies them to the model culture.
        /// </summary>
        /// <param name="obj"></param>
        public static void LoadTranslations(this ITranslatableObject obj, bool includeChildren = false)
        {
            var tn = obj.GetAnnotation("TabularEditor_TranslatedNames");

            if (tn != null)
            {
                obj.TranslatedNames.CopyFrom(DeserializeTranslations(tn));
            }

            var td = obj.GetAnnotation("TabularEditor_TranslatedDescriptions");

            if (td != null)
            {
                obj.TranslatedDescriptions.CopyFrom(DeserializeTranslations(td));
            }

            var tdf = obj.GetAnnotation("TabularEditor_TranslatedDisplayFolders");

            if (tdf != null && obj is IFolderObject)
            {
                (obj as IFolderObject).TranslatedDisplayFolders.CopyFrom(DeserializeTranslations(tdf));
            }

            if (includeChildren && obj is ITabularObjectContainer)
            {
                foreach (var child in (obj as ITabularObjectContainer).GetChildren().OfType <ITranslatableObject>())
                {
                    child.LoadTranslations(true);
                }
            }
        }
        /// <summary>
        /// Reads any translations stored in the annotations of the current instance of an ITranslatableObject,
        /// and applies them to the model culture.
        /// </summary>
        /// <param name="obj"></param>
        public static void LoadTranslations(this ITranslatableObject obj, bool includeChildren = false)
        {
            var tn = obj.GetAnnotation(AnnotationHelper.ANN_NAMES);

            if (tn != null)
            {
                obj.TranslatedNames.CopyFrom(DeserializeTranslations(tn));
                obj.RemoveAnnotation(AnnotationHelper.ANN_NAMES, false);
            }

            var td = obj.GetAnnotation(AnnotationHelper.ANN_DESCRIPTIONS);

            if (td != null)
            {
                obj.TranslatedDescriptions.CopyFrom(DeserializeTranslations(td));
                obj.RemoveAnnotation(AnnotationHelper.ANN_DESCRIPTIONS, false);
            }

            var tdf = obj.GetAnnotation(AnnotationHelper.ANN_DISPLAYFOLDERS);

            if (tdf != null && obj is IFolderObject)
            {
                (obj as IFolderObject).TranslatedDisplayFolders.CopyFrom(DeserializeTranslations(tdf));
                obj.RemoveAnnotation(AnnotationHelper.ANN_DISPLAYFOLDERS, false);
            }

            if (includeChildren && obj is ITabularObjectContainer)
            {
                foreach (var child in (obj as ITabularObjectContainer).GetChildren().OfType <ITranslatableObject>())
                {
                    child.LoadTranslations(true);
                }
            }
        }
Ejemplo n.º 5
0
 public static void CopyTranslationsFrom(this ITranslatableObject target, ITranslatableObject src)
 {
     target.TranslatedNames.CopyFrom(src.TranslatedNames);
     target.TranslatedDescriptions.CopyFrom(src.TranslatedDescriptions);
     if (target is IFolderObject && src is IFolderObject)
     {
         ((IFolderObject)target).TranslatedDisplayFolders.CopyFrom(((IFolderObject)src).TranslatedDisplayFolders);
     }
 }
Ejemplo n.º 6
0
        private static void ApplyTrans(string cultureName, ITranslatableObject obj, JToken trans, bool overwrite)
        {
            if (overwrite || string.IsNullOrEmpty(obj.TranslatedNames[cultureName]))
            {
                obj.TranslatedNames[cultureName] = trans.Value <string>("translatedCaption");
            }

            if (overwrite || string.IsNullOrEmpty(obj.TranslatedDescriptions[cultureName]))
            {
                obj.TranslatedDescriptions[cultureName] = trans.Value <string>("translatedDescription");
            }

            if (obj is IFolderObject)
            {
                var o = obj as IFolderObject;
                if (overwrite || string.IsNullOrEmpty(o.TranslatedDisplayFolders[cultureName]))
                {
                    o.TranslatedDisplayFolders[cultureName] = trans.Value <string>("translatedDisplayFolder");
                }
            }
        }
        /// <summary>
        /// Stores all translations on the current instance of an ITranslatableObject as annotations on the object.
        /// Translations can later be retrieved using the LoadTranslations() extension method.
        /// </summary>
        /// <param name="obj"></param>
        public static void SaveTranslations(this ITranslatableObject obj, bool includeChildren = false)
        {
            if (!obj.TranslatedNames.IsEmpty)
            {
                obj.SetAnnotation("TabularEditor_TranslatedNames", obj.TranslatedNames.ToJson(), false);
            }
            if (!obj.TranslatedDescriptions.IsEmpty)
            {
                obj.SetAnnotation("TabularEditor_TranslatedDescriptions", obj.TranslatedDescriptions.ToJson(), false);
            }
            if (obj is IFolderObject && !(obj as IFolderObject).TranslatedDisplayFolders.IsEmpty)
            {
                obj.SetAnnotation("TabularEditor_TranslatedDisplayFolders", (obj as IFolderObject).TranslatedDisplayFolders.ToJson(), false);
            }

            if (includeChildren && obj is ITabularObjectContainer)
            {
                foreach (var child in (obj as ITabularObjectContainer).GetChildren().OfType <ITranslatableObject>())
                {
                    child.SaveTranslations(true);
                }
            }
        }
        /// <summary>
        /// Stores all translations on the current instance of an ITranslatableObject as annotations on the object.
        /// Translations can later be retrieved using the LoadTranslations() extension method.
        /// </summary>
        /// <param name="obj"></param>
        public static void SaveTranslations(this ITranslatableObject obj, bool includeChildren = false)
        {
            if (!obj.TranslatedNames.IsEmpty)
            {
                obj.SetAnnotation(AnnotationHelper.ANN_NAMES, obj.TranslatedNames.ToJson(), false);
            }
            if (!obj.TranslatedDescriptions.IsEmpty)
            {
                obj.SetAnnotation(AnnotationHelper.ANN_DESCRIPTIONS, obj.TranslatedDescriptions.ToJson(), false);
            }
            if (obj is IFolderObject && !(obj as IFolderObject).TranslatedDisplayFolders.IsEmpty)
            {
                obj.SetAnnotation(AnnotationHelper.ANN_DISPLAYFOLDERS, (obj as IFolderObject).TranslatedDisplayFolders.ToJson(), false);
            }

            if (includeChildren && obj is ITabularObjectContainer)
            {
                foreach (var child in (obj as ITabularObjectContainer).GetChildren().OfType <ITranslatableObject>())
                {
                    child.SaveTranslations(true);
                }
            }
        }
Ejemplo n.º 9
0
        public static LanguageDataObject GetTranslation(string language, ITranslatableObject obj)
        {
            LanguageDataObject translation; 
			TryGetTranslation(out translation, language, obj);
            return translation;
        }
Ejemplo n.º 10
0
 public static LanguageDataObject GetTranslation(this GamePlayer player, ITranslatableObject obj)
 {
 	return player.Client.GetTranslation(obj);
 }
Ejemplo n.º 11
0
        public static LanguageDataObject GetTranslation(this GameClient client, ITranslatableObject obj)
        {
            LanguageDataObject translation;
			TryGetTranslation(out translation, client, obj);
            return translation;
        }
Ejemplo n.º 12
0
        public virtual string GetName(int article, bool firstLetterUppercase, string lang, ITranslatableObject obj)
        {
            switch (lang)
            {
                case "EN":
                    {
                        return GetName(article, firstLetterUppercase);
                    }
                default:
                    {
                        if (obj is GameNPC)
                        {
                            var translation = (DBLanguageNPC)LanguageMgr.GetTranslation(lang, obj);
                            if (translation != null) return translation.Name;
                        }

						return GetName(article, firstLetterUppercase);;
                    }
            }
        }
Ejemplo n.º 13
0
        public static bool TryGetTranslation(out LanguageDataObject translation, string language, ITranslatableObject obj)
        {
            if (obj == null)
            {
                translation = null;
                return(false);
            }

            if (Util.IsEmpty(language) || language == DefaultLanguage /*Use the objects base data (e.g. NPC.Name)*/)
            {
                translation = null;
                return(false);
            }

            translation = GetLanguageDataObject(language, obj.TranslationId, obj.TranslationIdentifier);
            return(translation == null ? false : true);
        }
Ejemplo n.º 14
0
        public static bool TryGetTranslation(out LanguageDataObject translation, GameClient client, ITranslatableObject obj)
        {
            if (client == null)
            {
                translation = null;
                return(false);
            }

            return(TryGetTranslation(out translation, (client.Account == null ? String.Empty : client.Account.Language), obj));
        }
Ejemplo n.º 15
0
 public static LanguageDataObject GetTranslation(GamePlayer player, ITranslatableObject obj)
 {
     return(GetTranslation(player.Client, obj));
 }
Ejemplo n.º 16
0
        public static bool TryGetTranslation(out LanguageDataObject translation, GameClient client, ITranslatableObject obj)
        {
            if (client == null)
            {
                translation = null;
                return false;
            }

            return TryGetTranslation(out translation, (client.Account == null ? String.Empty : client.Account.Language), obj);
        }
Ejemplo n.º 17
0
        public static bool TryGetTranslation(out LanguageDataObject translation, string language, ITranslatableObject obj)
        {
            if (obj == null)
            {
                translation = null;
                return false;
            }

            if (Util.IsEmpty(language) || language == DefaultLanguage /*Use the objects base data (e.g. NPC.Name)*/)
            {
                translation = null;
                return false;
            }

            translation = GetLanguageDataObject(language, obj.TranslationId, obj.TranslationIdentifier);
            return (translation == null ? false : true);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Returns a translation for the given client of the given translatable object.
        /// </summary>
        /// <param name="obj">The object you request a translation for.</param>
        /// <param name="client">The client you want the translation for.</param>
        /// <returns>DataObject or 'null' if nothing was found.</returns>
        public static DataObject GetTranslation(GameClient client, ITranslatableObject obj)
        {
            if (client == null || obj == null)
                return null;

            DataObject result = null;
            if (!Util.IsEmpty(obj.TranslationId))
            {
                eObjColKey key = eObjColKey.eNULL;

                if (obj is AbstractArea)
                    key = eObjColKey.eArea;
                else if (obj is GameStaticItem)
                {
                    if (obj is WorldInventoryItem)
                        return result; // Not supported yet
                    else
                        key = eObjColKey.eStaticObject;
                }
                else if (obj is GameNPC)
                    key = eObjColKey.eNPC;
                else if (obj is Zone)
                    key = eObjColKey.eZone;

                // No more checks, get the result as quick as possible - if exist
                // and all parameters / variables are valid!
                try
                {
                    result = m_objectTranslations[key][client.Account.Language.ToUpper()][obj.TranslationId];
                }
                catch
                {
                }
            }
            return result;
        }