Display overlay text in the UI
We still have fonts to do, so this is very ugly, but it at least shows *something* on the screen now.
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
// file that maps string IDs to messages
|
||||
type I18n struct {
|
||||
Name string
|
||||
mapping map[int]string
|
||||
mapping map[int]Entry
|
||||
}
|
||||
|
||||
// FIXME: this should be put into the config file maybe, or detected from a list
|
||||
@@ -22,6 +22,15 @@ const (
|
||||
I18nFile = "USEng.dta"
|
||||
)
|
||||
|
||||
// I18n entries may have 1 or 2 items. If two, the first is a menu item and the
|
||||
// second is a help string for that menu item.
|
||||
//
|
||||
// The text or help may contain some magic strings, as mentioned in USEng.data
|
||||
type Entry struct {
|
||||
Text string
|
||||
Help string
|
||||
}
|
||||
|
||||
func LoadI18n(filename string) (*I18n, error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
@@ -32,7 +41,7 @@ func LoadI18n(filename string) (*I18n, error) {
|
||||
|
||||
out := &I18n{
|
||||
Name: filepath.Base(filename),
|
||||
mapping: make(map[int]string),
|
||||
mapping: make(map[int]Entry),
|
||||
}
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
@@ -63,7 +72,12 @@ func LoadI18n(filename string) (*I18n, error) {
|
||||
|
||||
// TODO: Replace certain escape characters with their literals?
|
||||
|
||||
out.mapping[num] = string(val)
|
||||
if entry, ok := out.mapping[num]; !ok { // first time we've seen this
|
||||
out.mapping[num] = Entry{Text: string(val)}
|
||||
} else { // Second time, the item is help text
|
||||
entry.Help = string(val)
|
||||
out.mapping[num] = entry
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
@@ -78,8 +92,14 @@ func (n *I18n) Len() int {
|
||||
}
|
||||
|
||||
// Puts the internationalized string into `out` if `in` matches a known ID
|
||||
func (n *I18n) Replace(in int, out *string) {
|
||||
func (n *I18n) ReplaceText(in int, out *string) {
|
||||
if str, ok := n.mapping[in]; ok {
|
||||
*out = str
|
||||
*out = str.Text
|
||||
}
|
||||
}
|
||||
|
||||
func (n *I18n) ReplaceHelp(in int, out *string) {
|
||||
if str, ok := n.mapping[in]; ok {
|
||||
*out = str.Help
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user