Glitch9 Documentation
Glitch9 Inc.OpenAINative Plugins
  • Glitch9 Inc
    • Welcome to Glitch9 Inc.
  • Unity Toolkits
    • AI Development Kit
    • Smart Localization
      • Getting Started
    • Commit Gen
      • Getting Started
    • Serialization Saver
      • Getting Started
  • Native Plugins for Unity
    • Native Media Player
    • Status & Navigation Bar
      • Getting Started
      • Public Methods
      • Public Variables
      • Update Logs
    • Lock Task
      • API Reference
    • Background Music Looper
  • Support
    • How to setup Newtonsoft.Json
    • How to setup UniTask
Powered by GitBook
On this page
  • Requirements
  • Getting Started
  • Basic Usage
  1. Unity Toolkits
  2. Smart Localization

Getting Started

PreviousSmart LocalizationNextCommit Gen

Last updated 11 months ago

Requirements

Smart Localization requires the 'AI Development Kit' asset to function. Please ensure this asset is installed before using Smart Localization. If you do not have 'AI Development Kit' installed yet, you can download it from the Unity Asset Store

Getting Started

Smart Localization settings are managed through the Unity Preferences window. Follow these steps to configure your localization settings:

1. Open Preferences:

  • In Unity, navigate to Edit > Preferences... (on macOS, Unity > Preferences...).

  • In the Preferences window, select Glitch9 > Smart Localization.

2. General Settings:

  • Default Locale: Set the default language for your project.

  • Localization Source: Choose the source for your localization data (e.g., Addressables).

  • Addressable Group: Specify the addressable group that contains the localization tables.

5. Contributors:

  • Manage the list of contributors to your localization data.

6. Locales:

  • Available Locales: Configure the default set of locales available for use in the localization system.

  • Supported Locales: Specify the locales included in the current version of the project.

Basic Usage

1. Set the Current Locale:

First, set the locale that your application will use for localization. This can be done using the LocalizationManager.CurrentLocale property.

// Set the current locale to French
LocalizationManager.CurrentLocale = new Locale(SystemLanguage.French);

2. Localize Strings:

Use the provided extension methods to localize strings based on the current locale. The Localize extension method can be used to fetch the localized version of a string.

// Localize a string key using the default table
string localizedText = "hello_world".Localize();

// Localize a string key using a specified table
string localizedTextFromTable = "greeting".Localize("myCustomTable");

3. Localize DateTime:

The Localize extension method for DateTime allows you to format dates and times according to the current locale.

DateTime currentDate = DateTime.Now;

// Localize DateTime to the current locale with default format
string localizedDate = currentDate.Localize();

// Localize DateTime to the current locale with a specific format
string localizedDateWithFormat = currentDate.Localize(DateTimeFormat.FullDateWithDay);

4. Localize Enums:

To localize enums, you need to use the LocalizedEnumAttribute to specify the table name for the enum values. Then, you can use the Localize extension method for enums.

// Define the enum with the LocalizedEnum attribute
[LocalizedEnum("DaysTable")]
public enum DaysOfWeek
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}

// Localize an enum value
string localizedDay = DaysOfWeek.Monday.Localize();
here.