콘텐츠로 이동

언어관리

읽기 전...

모듈 설정시 .Init() 처럼 QuadId 란을 비워두는 경우 Lang 기능이 코드를 넘어 공유되지 않습니다
하지만 .Init("Project1") 처럼 아이디를 부여하는 경우 다른 모듈, 로컬스크립트가 접근하더라도 같은 QuadId 를 가졌다면 Lang 은 공유됩니다

Quad 에는 귀찮은 언어관리를 자동으로 해주는 기능이 내장되어 있습니다.
이 기능은 register 와 연동해 적은 줄의 코드로 변하는 텍스트도 언어에 맞게 출력되도록 만들 수 있습니다.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local ScreenGUI = script.Parent
local Quad = require(path.to.module).Init()
local Store = Quad.Store
local Mount = Quad.Mount
local Event = Quad.Event
local Lang = Quad.Lang
local Class = Quad.Class

local TextButton = Class "TextButton"

local myStore = Store.GetStore("myStore")
myStore.count = 0

Lang.New("TimePassed",{
    [Lang.Locales.Korean] = "{count}초 지났어요";
    [Lang.Locales.Default] = function (options)
        -- 함수 또한 등록할 수 있습니다.
        if options.count > 1 then
            return ("%d seconds passed"):format(options.count)
        else
            return ("%d second passed"):format(options.count)
        end
    end;
})

TextButton "mainButton" {
    Size = UDim2.fromOffset(100,100);
    Text = Lang "TimePassed" {
        -- count = 1 일반적인 값도 사용가능합니다
        count = myStore "count";
    };
    [Event "MouseButton1Click"] = function()
        -- 클릭시 언어가 변경됩니다
        if Lang.CurrentLocale == Lang.Locales.Default then
            Lang.CurrentLocale = Lang.Locales.Korean
        else
            Lang.CurrentLocale = Lang.Locales.Default
        end
    end
}
Mount(ScreenGUIk,Store.GetObject("mainButton"))

while task.wait(1) do
    myStore.count = myStore.count + 1
end

로케일 값들은 Lang.Locales에서 가져올 수 있으며, 사용가능한 로케일 목록은 다음과 같습니다.