Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow LUA widget translations #2275

Merged
merged 1 commit into from
Sep 7, 2022
Merged

Conversation

DavBfr
Copy link
Contributor

@DavBfr DavBfr commented Sep 5, 2022

Allows #221

Summary of changes:
Add the ability for Lua Widgets to display proper text in the Settings Menu as well as Display translated strings for Settings and The Widget name itself.

Backward compatibility is preserved as it adds a widget callback translate(text, lang) that is called if defined.

Example:

local name = "MyWidget"

local options = {
    {"FirstChannel", VALUE, 1},
    {"FillBackground", BOOL, 0},
    {"BgColor", COLOR, COLOR_THEME_SECONDARY3},
    {"TextColor", COLOR, COLOR_THEME_PRIMARY1},
    {"BarColor", COLOR, COLOR_THEME_SECONDARY1}
}

local function update(widget, options)
    widget.options = options
end

local function create(zone, options)
    local widget = {zone = zone, options = options}
    return widget
end

local function refresh(widget, event, touch)
end

local function translate(text, lang)
    local tr = {
        MyWidget = "My Widget",
        FirstChannel = "First Channel",
        FillBackground = "Fill Background?",
        BgColor = "Bg Color",
        TextColor = "Text Color",
        BarColor = "Color"
    }
    local tr_fr = {
        MyWidget = "Mon Gadget",
        FirstChannel = "Permier canal",
        FillBackground = "Remplir le fond ?",
        BgColor = "Couleur du fond",
        TextColor = "Couleur du texte",
        BarColor = "Couleur"
    }
    local v
    if lang == "FR" then
        v = tr_fr[text]
    else
        v = tr[text]
    end
    return v == nil and text or v
end

return {
    refresh = refresh,
    name = name,
    create = create,
    update = update,
    options = options,
    translate = translate
}

Screen Shot 2022-09-05 at 10 18 51

Screen Shot 2022-09-05 at 10 23 29

Screen Shot 2022-09-05 at 10 18 40

Screen Shot 2022-09-05 at 10 23 35

@pfeerick pfeerick added color Related generally to color LCD radios translation widget labels Sep 5, 2022
@pfeerick pfeerick added this to the 2.8 milestone Sep 5, 2022
@pfeerick
Copy link
Member

pfeerick commented Sep 7, 2022

Is the example code given compatible with the current Lua version and support? As I get errors as soon as I try it as things like const do not appear to be a Lua keyword in the limited Lua 5.2.2 engine currently in use ;) Pretty sure this was only added in 5.4

@DavBfr
Copy link
Contributor Author

DavBfr commented Sep 7, 2022

@pfeerick Sorry, that's not LUA at all. It's the right script now.

Copy link
Member

@pfeerick pfeerick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice indeed. I'm guessing the original example code you had up will be seen again in a future PR? 😁

@pfeerick pfeerick merged commit 4ed4f21 into EdgeTX:main Sep 7, 2022
@DavBfr
Copy link
Contributor Author

DavBfr commented Sep 7, 2022

Very nice indeed. I'm guessing the original example code you had up will be seen again in a future PR? 😁

No, it's just the original typescript code. The Lua script is transpiled from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
color Related generally to color LCD radios translation widget
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants