//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using System.Runtime.CompilerServices; namespace BansheeEngine { /** @addtogroup GUI_Engine * @{ */ /// /// Handle to a localized string. /// public sealed class LocString : ScriptObject { /// /// Creates a new empty localized string. /// public LocString() { Internal_CreateInstance(this, "", 0); } /// /// Creates a new empty localized string. /// /// Unique identifier of the string table to retrieve the string from. public LocString(int tableId) { Internal_CreateInstance(this, "", tableId); } /// /// Creates a new localized string with the specified identifier. If the identifier doesn't previously exist in /// the string table, identifier value will also be used for initializing the default language version of the string. /// /// String you can use for later referencing the localized string. /// Unique identifier of the string table to retrieve the string from. public LocString(string identifier, int tableId = 0) { Internal_CreateInstance(this, identifier, tableId); } /// /// Converts a normal string into a localized string by using the normal string as the identifier. /// /// Localized string identifier. /// Localized string with the provided identifier, from the default string table. public static implicit operator LocString(string identifier) { return new LocString(identifier); } /// /// Retrieves localized text for the active language from the localized string. /// /// Localized string to retrieve the text from. /// Translated text for the currently active language. public static explicit operator string(LocString text) { string value; Internal_GetValue(text.mCachedPtr, out value); return value; } /// /// Sets a value of a string parameter. Parameters are specified as bracketed values within the string itself /// (for example {0}, {1}) etc. Use ^ as an escape character. /// /// Index of the parameter to set. /// Value to insert at the parameter's position. public void SetParameter(int idx, string value) { Internal_SetParameter(mCachedPtr, idx, value); } [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_CreateInstance(LocString instance, string identifier, int tableId); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_SetParameter(IntPtr nativeInstance, int idx, string identifier); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_GetValue(IntPtr nativeInstance, out string value); } /** @} */ }