LocalizationService

Provides the text translation function.

# Properties

[{"index":"string CurrentLocaleId (ReadOnly)","0":"The current language code of the client. It's the language selected in the Language settings of released World, and Test Play Language settings in the Maker mode."}]

[{"index":"Translator LocalTranslator (ReadOnly)","0":"This Translator applies to CurrentLocaleId."}]

# Methods

[{"index":"string GetText(string key) (ClientOnly)","0":"Finds and returns the text of the cell whose row name is key and column name is CurrentLocaledId in the translation table."}]

[{"index":"string GetTextFormat(string key, any... args) (ClientOnly)","0":"Finds the text of the cell whose row name is key and column name is CurrentLocaledId in the translation table, and returns the result of filling in the values passed as args according to the format."}]

[{"index":"Translator GetTranslatorForLocale(string localeId) (ClientOnly)","0":"Returns the Translator corresponding to the entered localeId."}]

[{"index":"string SmartFormat(string format, any... args) (ClientOnly)","0":"Returns the result of filling in the values passed as args according to the format based on CurrentLocaleId."}]

##### inherited from Service:

[{"index":"EventHandlerBase ConnectEvent(string key, IScriptFunction eventHandler)","0":"Links events. When a key-type event occurs in this service, a handler is notified. The handler receives event parameters."}]

[{"index":"EventHandlerBase ConnectEvent(Type eventType, IScriptFunction eventHandler)","0":"Links events. This service notifies a handler when an eventType event occurs. The handler receives event parameters."}]

[{"index":"boolean DisconnectEvent(string key, EventHandlerBase eventHandler)","0":"Disconnects the event with the key-type event and the handler."}]

[{"index":"boolean DisconnectEvent(Type eventType, EventHandlerBase eventHandler)","0":"Disconnects the eventType event from its handler."}]

[{"index":"void SendEvent(EventType sendEvent)","0":"Generates an event."}]

# Examples

This example shows how to search text in LocaleDataSet and convert into the desired format. You can create the following in LocaleDataSet to use the example.

[{"Key":"TEXT_TEST1","Source":"Default Text","Note":"Normal Text Example","ko":"안녕","en":"Hello","Unnamed: 5":"nan"},{"Key":"TEXT_TEST2","Source":"Default Text","Note":"Simple Formatted Example","ko":"안녕, {0}!","en":"Hello, {0}!","Unnamed: 5":"nan"},{"Key":"TEXT_TEST3","Source":"Default Text","Note":"Smart Format Example (Korean)","ko":"안녕, {0}{0:hpp:아","en":"야}!","Unnamed: 5":"Hello, {0}!"},{"Key":"TEXT_TEST4","Source":"Default Text","Note":"Smart Format Example (English)","ko":"나는 사과 {0}개를 갖고 있다.","en":"I have {0:p:an apple","Unnamed: 5":"{} apples}."}]
    
    
    @Component
    script LocalizationDemo extends Component
        method void OnBeginPlay()
        -- Retrieves text according to the language setting of the current client.
        local plainText = _LocalizationService:GetText("TEXT_TEST1")
    
        -- Translator that only retrieves text corresponding to the English (en) column.
        local enTranslator = _LocalizationService:GetTranslatorForLocale("en")
    
        -- Translator that only retrieves text corresponding to the Korean (ko) column.
        local koTranslator = _LocalizationService.LocalTranslator
    
        local formatTextEn = enTranslator:GetTextFormat("TEXT_TEST2", "world")
        local formatTextKo = koTranslator:GetTextFormat("TEXT_TEST2", "세상")
        local formatTextHpp1 = koTranslator:GetTextFormat("TEXT_TEST3", "세상")
        local formatTextHpp2 = koTranslator:GetTextFormat("TEXT_TEST3", "세계")
        local formatTextPlural1 = enTranslator:GetTextFormat("TEXT_TEST4", 1)
        local formatTextPlural2 = enTranslator:GetTextFormat("TEXT_TEST4", 2)
    
        log("plainText: ", plainText)
        log("formatText: ", formatTextEn, "/", formatTextKo)
        log("Hpp format: ", formatTextHpp1, "/", formatTextHpp2)
        log("Plural format: ", formatTextPlural1, "/", formatTextPlural2)
    
        -- Fills the variable in the string based on the current language setting (ko).
        log(_LocalizationService:SmartFormat("안녕, {0:hpp:{}아|{}야}!", "친구"))
        log(_LocalizationService:SmartFormat("안녕, {0}{0:hpp:아|야}!", "세상"))
    
        -- Result --
        -- plainText:   Hello
        -- formatText:  Hello, world!   /   Hello, world!
        -- Hpp format: 안녕, 세상아!    /   안녕, 세계야!
        -- Plural format:   I have an apple.    /   I have 2 apples.
    
        -- 안녕, 친구야!
        -- 안녕, 세상아!
    
        -- I have an apple.
        -- I have 5 apples.
        end
    end
    

# SeeAlso

  * [LocaleDataSet](/docs?postId=1120)
  * [Localizing Formats](/docs?postId=968)
  * [Understanding Localization](/docs?postId=951)