Skip to content

Localisation

Dan edited this page Jan 31, 2024 · 1 revision

Implementing Localization in Cities Skylines 2 Mods Using Gooee

Overview

Localization is a crucial aspect of mod development, allowing your mod to reach a broader audience by supporting multiple languages. In the Gooee framework for Cities Skylines 2, you can implement localization by defining the IGooeeLanguages interface and using embedded resource YAML files for language translations.

Step 1: Setting Up Your Plugin for Localization

Your plugin class needs to implement the IGooeeLanguages interface, along with the IGooeePluginWithControllers interface. This setup allows your plugin to support multiple languages. Here's an example of how to define your plugin class for localization:

[ControllerTypes(typeof(ExampleController))]
public class ExamplePlugin : IGooeePluginWithControllers, IGooeeLanguages
{
    public string Name => "Example";
    public string ScriptResource => "MyAssembly.Resources.ui.js";
    public string LanguageResourceFolder => "MyAssembly.Resources.lang";

    public IController[] Controllers { get; set; }
}

Step 2: Understanding the LanguageResourceFolder Property

The LanguageResourceFolder property in your plugin class should point to the folder within your assembly where your language YAML files are located. This folder will contain all the necessary translations for your mod.

Step 3: Creating Localization Files

Localization files should be created as embedded resources within the "lang" folder in your assembly. Each file corresponds to a specific locale and is named after the locale's code (e.g., "en-US"). The file format is YAML, and the structure is straightforward:

lang:
  Key: "Translated Text String"

Example of a Localization File (en-US.yml)

lang:
  WelcomeMessage: "Welcome to the Example mod!"
  SettingsTitle: "Settings"
  EnableFeature: "Enable Feature"

Step 4: Using Localization in Your Mod

Once you have set up your localization files, you can use the game's built-in localization methods to retrieve and display the translated strings in your mod's UI. These methods will be documented separately, detailing how to fetch and apply these translations dynamically based on the user's language settings.

Step 5: Testing Localization

It's important to test your mod with different language settings to ensure that the localization works correctly and that all text is displayed properly in the selected language.

Conclusion

By implementing the IGooeeLanguages interface and setting up localized YAML files in your Cities Skylines 2 mod, you can easily support multiple languages, making your mod more accessible and user-friendly for a global audience. Stay tuned for additional documentation on using the game's built-in localization methods.

Clone this wiki locally