mirror of
https://github.com/rivo/tview.git
synced 2026-04-26 21:35:54 +03:00
[GH-ISSUE #463] Translation strategy / demo #332
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/tview#332
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mpictor on GitHub (Jun 24, 2020).
Original GitHub issue: https://github.com/rivo/tview/issues/463
This is the first time I've dealt with translations, and I'm not certain of the best approach. I'm writing an app which needs to ask the user some configuration questions; currently I'm using tview.Pages, each with a simple form. The first question (first page) asks the user to select a language. When they do, I want translatable strings on all pages to update.
Currently I am defining all pages in the UI before the language question is asked, but it seems there's no easy way to enumerate the elements and change their text. I'm also not seeing a way to define elements that only load their text when they become visible; it'd be nice for my use case but I suppose this use case is an exception.
My current thinking is that it'll be best to delete and re-define pages in the ui when the language changes - or to only allow the language to be set once, and only define the remaining pages after the language is set.
Does this approach make sense to you? Is it how you'd do things?
I was also wondering if you'd create a demo showing how you'd approach the problem.
If it helps, this is what I'm doing for translations:
I'm using a to-be-written package
xlate. In that package,func T(string)stringtakes a string in the default language and looks it up in the translation resource matching the string varLanguage, returning the appropriate string for that language.Thanks for writing tview, I'm finding it quite useful!
@rivo commented on GitHub (Jun 28, 2020):
The question is whether there are any users at all who will change the language mid-way through such a configuration walkthrough. Personally, I've never done that. I would think it's ok to create all pages, translated, after the first form which is "Select your language".
Of course, if your forms are complex, it can be a bit difficult to change all labels and texts. There is
Form.GetFormItem()but you'll still need to cast to the actual Primitive type (e.g. usingswitch). I would think it's possible. Let me know if there is a specific function that you're missing.Another alternative is to create pages for all languages but only show the ones for the language that was picked. Since you can name pages, you could append language codes, e.g. "config1_en" and "config1_el".
@rivo commented on GitHub (Jul 12, 2020):
If there are no follow-up questions, I'll close this issue soon.
@mpictor commented on GitHub (Jul 13, 2020):
Thanks. What I ended up doing was re-creating all pages whenever the language changes. This means the user can go back and switch languages, if desired - and I don't have to iterate through the items/determine type/etc.