mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-14 15:11:25 -07:00
[i18n] Initial i18n support.
- Add initial GetText .MO parser - Add translation struct and helpers - Pluralized lookup TODO: - Support for more translation catalog file formats.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package i18n_example
|
||||
|
||||
import "core:mem"
|
||||
import "core:fmt"
|
||||
import "core:i18n"
|
||||
|
||||
LOC :: i18n.get
|
||||
|
||||
_main :: 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(LOC(""))
|
||||
println("-----")
|
||||
println(LOC("There are 69,105 leaves here."))
|
||||
println("-----")
|
||||
println(LOC("Hellope, World!"))
|
||||
|
||||
/*
|
||||
For ease of use, pluralized lookup can use both singular and plural form as key for the same translation.
|
||||
*/
|
||||
println("-----")
|
||||
printf(LOC("There is %d leaf.\n", 1), 1)
|
||||
printf(LOC("There is %d leaf.\n", 42), 42)
|
||||
|
||||
printf(LOC("There are %d leaves.\n", 1), 1)
|
||||
printf(LOC("There are %d leaves.\n", 42), 42)
|
||||
|
||||
/*
|
||||
This isn't.
|
||||
*/
|
||||
println("-----")
|
||||
println(LOC("Come visit us on Discord!"))
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
using fmt
|
||||
|
||||
track: mem.Tracking_Allocator
|
||||
mem.tracking_allocator_init(&track, context.allocator)
|
||||
context.allocator = mem.tracking_allocator(&track)
|
||||
|
||||
_main()
|
||||
|
||||
if len(track.allocation_map) > 0 {
|
||||
println()
|
||||
for _, v in track.allocation_map {
|
||||
printf("%v Leaked %v bytes.\n", v.location, v.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.
@@ -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"
|
||||
Reference in New Issue
Block a user