using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace BansheeEngine
{
///
/// Used for string localization. Stores strings and their translations in various languages.
///
public sealed class StringTable : Resource
{
///
/// Constructor for runtime use only.
///
/// Dummy parameter to differentiate from the normal constructor.
private StringTable(bool dummy)
{ }
///
/// Creates a new empty string table.
///
public StringTable()
{
Internal_CreateInstance(this);
}
///
/// Returns the total number of strings in the table.
///
public int StringCount
{
get { return Internal_GetNumStrings(mCachedPtr); }
}
///
/// Returns all identifiers that the string table contains localized strings for.
///
public string[] Identifiers
{
get { return Internal_GetIdentifiers(mCachedPtr); }
}
///
/// Adds or modifies string translation for the specified language.
///
/// Identifier of the string to add/modify.
/// Language to add/modify the translation for.
/// Translated string in the specified language.
public void SetString(string identifier, Language language, string value)
{
Internal_SetString(mCachedPtr, identifier, language, value);
}
///
/// Adds or modifies string translation for the currently active language.
///
/// Identifier of the string to add/modify.
/// Translated string in the active language.
public void SetString(string identifier, string value)
{
Internal_SetStringDefault(mCachedPtr, identifier, value);
}
///
/// Removes the string described by identifier, from all languages.
///
/// Identifier of the string to remove.
public void RemoveString(string identifier)
{
Internal_RemoveString(mCachedPtr, identifier);
}
///
/// Returns a string translation for the specified language.
///
/// Identifier of the string to look up.
/// Language to retrieve the translation for.
/// String translation for the specified language. Returns the identifier itself if one doesn't exist.
///
public string GetString(string identifier, Language language)
{
string value;
Internal_GetString(mCachedPtr, identifier, language, out value);
return value;
}
///
/// Returns a string translation for the currently active language.
///
/// Identifier of the string to look up.
/// String translation for the active language. Returns the identifier itself if one doesn't exist.
///
public string GetString(string identifier)
{
string value;
Internal_GetStringDefault(mCachedPtr, identifier, out value);
return value;
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(StringTable instance);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern int Internal_GetNumStrings(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string[] Internal_GetIdentifiers(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetString(IntPtr thisPtr, string identifier, Language language, string value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetStringDefault(IntPtr thisPtr, string identifier, string value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_RemoveString(IntPtr thisPtr, string identifier);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_GetString(IntPtr thisPtr, string identifier, Language language, out string value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_GetStringDefault(IntPtr thisPtr, string identifier, out string value);
}
}