[i18n] Move to core:text/i18n.

This commit is contained in:
Jeroen van Rijn
2022-04-29 13:02:40 +02:00
parent 1289c96e2c
commit 2e11a8da5b
7 changed files with 3 additions and 2 deletions
+99
View File
@@ -0,0 +1,99 @@
package i18n_example
import "core:mem"
import "core:fmt"
import "core:text/i18n"
_T :: i18n.get
mo :: proc() {
using fmt
err: i18n.Error
/*
Parse MO file and set it as the active translation so we can omit `get`'s "catalog" parameter.
*/
i18n.ACTIVE, err = i18n.parse_mo(#load("nl_NL.mo"))
defer i18n.destroy()
if err != .None { return }
/*
These are in the .MO catalog.
*/
println("-----")
println(_T(""))
println("-----")
println(_T("There are 69,105 leaves here."))
println("-----")
println(_T("Hellope, World!"))
/*
For ease of use, pluralized lookup can use both singular and plural form as key for the same translation.
This is a quirk of the GetText format which has separate keys for their different plurals.
*/
println("-----")
printf(_T("There is %d leaf.\n", 1), 1)
printf(_T("There is %d leaf.\n", 42), 42)
printf(_T("There are %d leaves.\n", 1), 1)
printf(_T("There are %d leaves.\n", 42), 42)
/*
This isn't.
*/
println("-----")
println(_T("Come visit us on Discord!"))
}
qt :: proc() {
using fmt
err: i18n.Error
/*
Parse QT file and set it as the active translation so we can omit `get`'s "catalog" parameter.
*/
i18n.ACTIVE, err = i18n.parse_qt(#load("../../../../tests/core/assets/XML/nl_NL-qt-ts.ts"))
defer i18n.destroy()
fmt.printf("parse_qt returned %v\n", err)
if err != .None {
return
}
/*
These are in the .TS catalog.
*/
println("--- Page section ---")
println("Page:Text for translation =", _T("Page", "Text for translation"))
println("-----")
println("Page:Also text to translate =", _T("Page", "Also text to translate"))
println("-----")
println("--- installscript section ---")
println("installscript:99 bottles of beer on the wall =", _T("installscript", "99 bottles of beer on the wall"))
println("-----")
println("--- apple_count section ---")
println("apple_count:%d apple(s) =")
println("\t 1 =", _T("apple_count", "%d apple(s)", 1))
println("\t 42 =", _T("apple_count", "%d apple(s)", 42))
}
main :: proc() {
using fmt
track: mem.Tracking_Allocator
mem.tracking_allocator_init(&track, context.allocator)
context.allocator = mem.tracking_allocator(&track)
// mo()
qt()
if len(track.allocation_map) > 0 {
println()
for _, v in track.allocation_map {
printf("%v Leaked %v bytes.\n", v.location, v.size)
}
}
}
+30
View File
@@ -0,0 +1,30 @@
# Odin i18n Example
# Copyright (C) 2021 Jeroen van Rijn
# This file is distributed under the same license as the PACKAGE package.
# Jeroen van Rijn <Kelimion@users.noreply.github.com>, 2021.
#
#, fuzzy
msgid ""
msgstr "Project-Id-Version: Example 0.0.1\n"
"Report-Msgid-Bugs-To: Jeroen van Rijn <Kelimion@users.noreply.github.com>\n"
"POT-Creation-Date: 2021-11-27 19:23+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en-GB\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: i18n_example.odin:28
msgid "There are 69,105 leaves here."
msgstr "Er zijn hier 69.105 bladeren."
#: i18n_example.odin:30
msgid "Hellope, World!"
msgstr "Hallo, Wereld!"
#: i18n_example.odin:36
msgid "There is %d leaf.\n"
msgid_plural "There are %d leaves.\n"
msgstr[0] "Er is %d blad.\n"
msgstr[1] "Er zijn %d bladeren.\n"
Binary file not shown.
+33
View File
@@ -0,0 +1,33 @@
# Odin i18n Example
# Copyright (C) 2021 Jeroen van Rijn
# This file is distributed under the same license as the PACKAGE package.
# Jeroen van Rijn <Kelimion@users.noreply.github.com>, 2021.
#
msgid ""
msgstr ""
"Project-Id-Version: Example 0.0.1\n"
"Report-Msgid-Bugs-To: Jeroen van Rijn <Kelimion@users.noreply.github.com>\n"
"POT-Creation-Date: 2021-11-27 19:23+0100\n"
"PO-Revision-Date: 2021-11-28 02:56+0100\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language-Team: Odin Language Team\n"
"X-Generator: Poedit 3.0\n"
"Last-Translator: Jeroen van Rijn\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: nl_NL\n"
#: i18n_example.odin:28
msgid "There are 69,105 leaves here."
msgstr "Er zijn hier 69.105 bladeren."
#: i18n_example.odin:30
msgid "Hellope, World!"
msgstr "Hallo, Wereld!"
#: i18n_example.odin:36
msgid "There is %d leaf.\n"
msgid_plural "There are %d leaves.\n"
msgstr[0] "Er is %d blad.\n"
msgstr[1] "Er zijn %d bladeren.\n"