> For the complete documentation index, see [llms.txt](https://docs.candy-smith.com/main/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.candy-smith.com/main/match-3-kit-home-design/localization/overview.md).

# Overview

## Localization System Documentation

This document outlines how to use the localization system in your project.

### Overview

The localization system allows you to easily translate text in your game to different languages. It uses a key-based approach where you assign a unique key to each piece of text, and then provide translations for those keys in separate language files.

### Setting Up

1. Create a text file for each language you want to support (e.g., `English.txt`, `Spanish.txt`) in the `Resources/Localization/` folder.
2. In each language file, add your translations in the format `KEY : Translation`.

### Using Localized Text

#### In Code

To get localized text in your scripts:

```csharp
localizedText = LocalizationManager.GetText("KEY", "Default Text");
```

The second parameter is the default text to use if the key is not found.

#### In UI

For UI elements, use the `LocalizedTextMeshProUGUI` component instead of the regular `TextMeshProUGUI`:

1. Add the `LocalizedTextMeshProUGUI` component to your UI text element.
2. Set the `Instance ID` field to the key you want to use for this text.
3. Set the default text in the regular text field of the component.

### Language Files

Each language file should be a plain text file with key-value pairs:

```
KEY : Translation
ANOTHER_KEY : Another translation
```

### Placeholders

You can use placeholders in your translations for dynamic content. The system supports replacing placeholders using the `PlaceholderManager`.

#### Level Number Placeholder

For level numbers, use the following format in your translations:

```
LEVEL : Level {level}
```

In your code, you would then use:

```csharp
string levelText = LocalizationManager.GetText("LEVEL", "Level {level}");
levelText = PlaceholderManager.ReplacePlaceholders(levelText, new Dictionary<string, string> { { "level", currentLevel.ToString() } });
```

### Changing Languages

To change the current language:

```csharp
LocalizationManager.LoadLanguage(SystemLanguage.French);
```

### Automatic Language Detection

The system automatically detects the system language on non-editor platforms. In the Unity editor, it uses the language specified in the `DebugSettings` asset.

### Best Practices

1. Use descriptive keys that reflect the content or purpose of the text.
2. Keep your language files organized and consistent across all supported languages.
3. Test your localization with placeholder text to ensure UI elements adapt to different text lengths.
4. Regularly update your language files as you add new text to your game.

By following these guidelines, you can efficiently manage translations for your game across multiple languages.
