Skip to main content

Register

Shared
Lyn.I18n.Register(table extensions)Function

Description

You can register additional extensions for localization using this function.

Mostly this will be used inside sh_modules/my_module.lua, have it in the top of the file. (Before any usage)

Params

  1. table extensions

Example:

addons/lyn_greet_module/lua/lyn/sh_modules/lyn_greet_module.lua

local Lyn = Lyn
local Command = Lyn.Command

Command.SetCategory("Chat")

Lyn.I18n.Register({
en = {
welcome_message = "Welcome, {P}!",
commands = {
greet = {
help = "Sends a greeting message to the specified player.",
notify = "{P} have greeted {T}: {green %message%}",
},
}
},
["zh-cn"] = {
welcome_message = "欢迎, {P}!",
commands = {
greet = {
help = "向指定玩家发送问候消息。",
notify = "{P} 向 {T} 打了个招呼: {green %message%}",
},
}
},
})

Command("greet")
:Permission("greet", "user")

:Param("player", { single_target = true, allow_higher_target = true })
:Param("string", {
hint = "message",
check = function(ctx)
local value = ctx.value
return value and value:match("%S") ~= nil
end
})
:GetRestArgs()
:Execute(function(ply, targets, message)
LYN_NOTIFY("*", "#lyn.commands.greet.notify", {
P = ply,
T = targets,
message = message,
})
end)
:Add()

if CLIENT then
hook.Add("Lyn.Player.Auth", "greetings", function(ply)
Lyn.Player.Chat.Add("#lyn.welcome_message", { P = ply })
end)
end