Localization - VirtueSky/sunflower_2 GitHub Wiki

Open tab Localization in Magic Panel (Sunflower > Magic Panel > Localization or short cut Alt/Option + 1 > Localization)

Screenshot 2025-03-31 171854

Setting

  • Avaiable Languages: List of languages supported in game localization
  • Detect Device Language: First time open app using device language to display locale
  • Google Translate API Key: API Keys are generated from the Credentials menu in API & Serivces on the Google Play Cloud Console

image

  • Spreasheet Key: your google sheet identifier, from your browser's address bar, you can extract your Google Sheet identifier. The format is like this:

image

  • Service Account Credential First, visit Google API Console. Pick API & Services > Credentials from sidebar menu.

Create project if you don't have any. Then pick Create Credentials > Service Account.

image

Then please fill in all information

image

Then create successful now you can get key service account Credential by click your new service account and select Keys tab. Pick Add Key > Create New Key.

image

image

After you have downloaded this key, copy its contents and fill in the Service Account Credential field

Note that you need to enable Google Sheet API service on google cloud console

image

Now go back to your google sheet and share this sheet with the email of the service account you just created so this account has access

image

At this point, you can press the import button right next to the spreadsheet field to retrieve all the data from the google sheet and create new locale text if not available. If available, the content will be updated, including changes. like adding a new language

Explore

Screenshot 2025-03-31 at 21 35 43

Button in bottom bar

  • Setting : select locale setting
  • Reload : reload data display in explore tree
  • Create : menu create locale asset
  • Rename : rename selected locale in tree
  • Delete : delete selected locale asset in tree
  • Import : Import locale data from csv file
  • Export : Export current locale data in project to csv file
  • Translate By : Translate current selected locale asset in tree (only languages have field empty was translated)
  • Translate All : Translate all locale asset in project
  • Fill All Localetext: Sync language for all locale text same with list AvailableLanguage
  • AppLanguage : button change current language using in project
  • Button Plus : add language for selected locale asset
  • Button Minus : remove language in selected locale asset

Usages

Create locale asset

  • Option 1: Use button create in bottom bar (Explore tab)

Screenshot 2025-03-31 at 21 56 59

  • Option 2: Right click on folder > Create > Sunflower > Localization > (Select locale asset)

Screenshot 2025-03-31 at 21 51 08

Locale asset after created

Screenshot 2025-03-31 at 21 59 51

Attach locale component in to object you want to localization (ex: LocaleTextComponent, LocaleFontComponent, LocaleMaterialComponent...)

Screenshot 2025-03-31 at 22 06 21

For example, here we will localize Text loading x% in the game, we will add component LocaleTextComponent which will automatically receive components and properties if the object contains Text or TextMeshProUGUI component.

We will drag the LocaleText asset into the variable. If the text changes value like (Loading 10%, Loading 20%, Loading 30%...) we will use format args because the text level here has only one arg so the Format Args array will only have one element. In localeText text_loading we fill in the text as follows

Screenshot 2025-03-31 at 22 08 35

Now we want to change the value of the text loading somewhere else, instead of declaring TextMeshProUGUI and changing the text as before, we will declare LocaleTextComponent and use the UpdateArgs function.

[SerializeField] private LocaleTextComponent localeTextComponent;

private void OnValueChanged(int percent) { localeTextComponent.UpdateArgs($"{percent}"); }