i18n is hard
This commit is contained in:
1 parent
c424541b35
commit
a646c32939
14 files changed
+200
-39
No files matched your search
@@ -12,9 +12,10 @@ lang_to_strings = defaultdict(set)
|
||||
DEFAULT_LANG = "en"
|
||||
|
||||
po = {}
|
||||
pofile = {}
|
||||
for lang in locales:
|
||||
pofile = os.path.join(localedir, lang, 'LC_MESSAGES', 'katrain.po')
|
||||
po[lang] = polib.pofile(pofile)
|
||||
pofile[lang] = os.path.join(localedir, lang, 'LC_MESSAGES', 'katrain.po')
|
||||
po[lang] = polib.pofile(pofile[lang])
|
||||
for entry in po[lang].translated_entries():
|
||||
if 'TODO' in entry.comment:
|
||||
print(lang,'/',entry.msgid,'is TODO')
|
||||
@@ -33,8 +34,8 @@ for lang in locales:
|
||||
po[lang].append(entry)
|
||||
else:
|
||||
print(f"MISSING IN DEFAULT AND {lang}",strings_to_langs[msgid])
|
||||
po[lang].save(pofile)
|
||||
mofile = pofile.replace('.po', '.mo')
|
||||
po[lang].save(pofile[lang])
|
||||
mofile = pofile[lang].replace('.po', '.mo')
|
||||
po[lang].save_as_mofile(mofile)
|
||||
print('Fixed',pofile,'and converted ->',mofile)
|
||||
print('Fixed',pofile[lang],'and converted ->',mofile)
|
||||
|
||||
@@ -2,6 +2,9 @@ import os
|
||||
from typing import Any, List, Tuple
|
||||
from kivy.lang import Observable
|
||||
import gettext
|
||||
from kivy.uix.label import Label
|
||||
from kivy.uix.textinput import TextInput
|
||||
from kivy.core.text import Label as CoreLabel
|
||||
|
||||
try:
|
||||
import importlib.resources as pkg_resources
|
||||
@@ -71,6 +74,7 @@ class Lang(Observable):
|
||||
def funbind(self, name, func, *args, **kwargs):
|
||||
if name == "_":
|
||||
key = (func, args, kwargs)
|
||||
print('funbind',key in self.observers)
|
||||
if key in self.observers:
|
||||
self.observers.remove(key)
|
||||
else:
|
||||
@@ -85,8 +89,19 @@ class Lang(Observable):
|
||||
|
||||
# update all the kv rules attached to this text
|
||||
for func, args, kwargs in self.observers:
|
||||
try:
|
||||
func(args[0], None, None)
|
||||
except ReferenceError:
|
||||
pass # proxy no longer exists
|
||||
|
||||
LANGUAGE = "nl"
|
||||
i18n = Lang(LANGUAGE)
|
||||
|
||||
class I18NLabel(Label):
|
||||
pass
|
||||
|
||||
class I18NCoreLabel(CoreLabel):
|
||||
pass
|
||||
|
||||
class I18NTextInput(TextInput):
|
||||
pass
|
||||
Binary file not shown.
@@ -0,0 +1,91 @@
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
+21
-12
@@ -1,5 +1,6 @@
|
||||
#:kivy 1.11.0
|
||||
#:import i18n __main__.i18n
|
||||
#:import find_package_resource __main__.find_package_resource
|
||||
|
||||
#:set BUTTON_COLOR [0.23, 0.30, 0.35, 1]
|
||||
#:set TOOLTIP_COLOR [0.43, 0.50, 0.65, 1]
|
||||
@@ -26,6 +27,14 @@
|
||||
#:set BOX_BACKGROUND_COLOR [46/255,65/255,88/255,1]
|
||||
#:set TEXT_COLOR WHITE
|
||||
|
||||
<I18NLabel>:
|
||||
font_name: i18n._('Roboto')
|
||||
|
||||
<I18NCoreLabel>:
|
||||
font_name: i18n._('Roboto')
|
||||
|
||||
<I18NTextInput>:
|
||||
font_name: i18n._('Roboto')
|
||||
|
||||
# mixins
|
||||
<OutlineColor>:
|
||||
@@ -69,7 +78,7 @@
|
||||
text_color: WHITE
|
||||
md_bg_color: BOX_BACKGROUND_COLOR
|
||||
label: label
|
||||
Label:
|
||||
I18NLabel:
|
||||
id: label
|
||||
text: root.text
|
||||
size_hint_x: None
|
||||
@@ -231,7 +240,7 @@
|
||||
text: root.label
|
||||
font_size: self.size[1] * 0.8
|
||||
on_press: value.opacity = 1 if value.opacity==0 else 0
|
||||
Label:
|
||||
I18NLabel:
|
||||
size_hint: 0.4,1
|
||||
text: root.text
|
||||
color: root.color
|
||||
@@ -248,7 +257,7 @@
|
||||
size: (root.min_size,root.min_size)
|
||||
source: 'img/white.png' if root.player=='White' else 'img/black.png'
|
||||
mipmap: True
|
||||
Label:
|
||||
I18NLabel:
|
||||
text: root.text
|
||||
bold: True
|
||||
color: BLACK if root.player=='White' else WHITE
|
||||
@@ -392,9 +401,9 @@
|
||||
MDBoxLayout:
|
||||
size_hint: 0.75, 1
|
||||
orientation: 'vertical'
|
||||
Label:
|
||||
I18NLabel:
|
||||
text: root.name
|
||||
Label:
|
||||
I18NLabel:
|
||||
text: root.description
|
||||
|
||||
|
||||
@@ -459,7 +468,7 @@
|
||||
#:set GRAPH_CENTER_COLOR GREY
|
||||
|
||||
|
||||
<GraphMarkerLabel@Label>:
|
||||
<GraphMarkerLabel@I18NLabel>:
|
||||
valign: 'bottom'
|
||||
halign: 'left'
|
||||
text: '+0'
|
||||
@@ -569,7 +578,7 @@
|
||||
bar_width: 5
|
||||
bar_color: BUTTON_COLOR
|
||||
label: label
|
||||
Label:
|
||||
I18NLabel:
|
||||
id: label
|
||||
markup: root.markup
|
||||
padding: 5, 5
|
||||
@@ -774,16 +783,16 @@
|
||||
Line:
|
||||
rectangle: (*self.pos,*self.size)
|
||||
width: 1
|
||||
SizedMDFlatButton:
|
||||
text: i18n._('Dutch')
|
||||
on_press: app.language = 'nl'
|
||||
size_hint: 1/3,1
|
||||
SizedMDFlatButton:
|
||||
text: i18n._('English')
|
||||
on_press: app.language = 'en'
|
||||
size_hint: 1/3,1
|
||||
SizedMDFlatButton:
|
||||
text: i18n._('Ko')
|
||||
text: i18n._('Dutch')
|
||||
on_press: app.language = 'nl'
|
||||
size_hint: 1/3,1
|
||||
SizedMDFlatButton:
|
||||
text: i18n._('Korean')
|
||||
on_press: app.language = 'ko'
|
||||
size_hint: 1/3,1
|
||||
Label:
|
||||
|
||||
@@ -11,7 +11,7 @@ from kivymd.uix.boxlayout import MDBoxLayout
|
||||
from kivymd.uix.floatlayout import MDFloatLayout
|
||||
from kivymd.uix.menu import MDDropdownMenu
|
||||
|
||||
from katrain.core.common import OUTPUT_DEBUG, evaluation_class, PLAYER_AI
|
||||
from katrain.core.common import OUTPUT_DEBUG, evaluation_class, PLAYER_AI, i18n
|
||||
from katrain.core.game import Move
|
||||
from katrain.gui.kivyutils import draw_circle, draw_text
|
||||
from katrain.core.common import var_to_grid
|
||||
@@ -288,9 +288,9 @@ class BadukPanWidget(Widget):
|
||||
passed = len(nodes) > 1 and current_node.is_pass
|
||||
if passed:
|
||||
if game_ended:
|
||||
text = katrain.game.manual_score or "game\nend"
|
||||
text = katrain.game.manual_score or i18n._("board-game-end")
|
||||
else:
|
||||
text = "pass"
|
||||
text = i18n._("board-pass")
|
||||
Color(0.45, 0.05, 0.45, 0.7)
|
||||
center = (self.gridpos_x[int(board_size_x / 2)], self.gridpos_y[int(board_size_y / 2)])
|
||||
size = min(self.width, self.height) * 0.22
|
||||
|
||||
@@ -54,8 +54,6 @@ class ScoreGraph(BackgroundColor):
|
||||
self.score_scale = max(math.ceil( max(-score_values_range[0], score_values_range[1]) / score_granularity),1) * score_granularity
|
||||
self.winrate_scale = max(math.ceil(max(-winrate_values_range[0], winrate_values_range[1]) / winrate_granularity), 1) * winrate_granularity
|
||||
|
||||
print(self.score_scale,score_values_range,score_values)
|
||||
|
||||
xscale = self.width / max(len(score_values) - 1, 15)
|
||||
available_height = self.height
|
||||
score_line_points = [[self.pos[0] + i * xscale, self.pos[1] + self.height / 2 + available_height / 2 * (val / self.score_scale)] for i, val in enumerate(score_values)]
|
||||
|
||||
+10
-11
@@ -3,8 +3,6 @@ import random
|
||||
import re
|
||||
|
||||
from kivy.clock import Clock
|
||||
from kivy.core.text import Label as CoreLabel
|
||||
from kivy.uix.label import Label
|
||||
from kivy.core.window import Window
|
||||
from kivy.graphics import *
|
||||
from kivy.properties import BooleanProperty, ListProperty, NumericProperty, StringProperty, OptionProperty, ObjectProperty
|
||||
@@ -12,9 +10,9 @@ from kivy.uix.behaviors import ToggleButtonBehavior, ButtonBehavior
|
||||
from kivy.uix.button import Button
|
||||
from kivy.uix.checkbox import CheckBox
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.label import Label
|
||||
from kivy.uix.scrollview import ScrollView
|
||||
from kivy.uix.spinner import Spinner
|
||||
from kivy.uix.textinput import TextInput
|
||||
from kivy.uix.widget import Widget
|
||||
|
||||
|
||||
@@ -26,12 +24,12 @@ from kivymd.uix.button import BasePressedButton, BaseFlatButton
|
||||
from kivymd.uix.floatlayout import MDFloatLayout
|
||||
from kivymd.uix.navigationdrawer import MDNavigationDrawer
|
||||
|
||||
from katrain.core.common import i18n
|
||||
from katrain.core.common import i18n, I18NLabel, I18NTextInput, I18NCoreLabel
|
||||
|
||||
#
|
||||
|
||||
# --- new mixins
|
||||
|
||||
|
||||
|
||||
class BackgroundColor(Widget):
|
||||
background_color = ListProperty([1, 1, 1, 0])
|
||||
|
||||
@@ -104,7 +102,7 @@ class TransparentIconButton(CircularRippleBehavior,Button):
|
||||
|
||||
|
||||
# -- basic styles
|
||||
class LightLabel(Label):
|
||||
class LightLabel(I18NLabel):
|
||||
pass
|
||||
|
||||
|
||||
@@ -201,8 +199,9 @@ class CollapsablePanel(MDBoxLayout):
|
||||
for button in self.option_buttons:
|
||||
self.header.add_widget(button)
|
||||
self.header.add_widget(Label()) # spacer
|
||||
self.trigger_select()
|
||||
else:
|
||||
self.header.add_widget(Label(text=i18n._(self.closed_label),halign='right',height=self.options_height))
|
||||
self.header.add_widget(I18NLabel(text=i18n._(self.closed_I18NLabel),halign='right',height=self.options_height))
|
||||
self.header.add_widget(self.open_close_button)
|
||||
|
||||
super().clear_widgets()
|
||||
@@ -247,7 +246,7 @@ class CollapsablePanel(MDBoxLayout):
|
||||
# --- not checked
|
||||
|
||||
|
||||
class ToolTipLabel(Label):
|
||||
class ToolTipLabel(I18NLabel):
|
||||
pass
|
||||
|
||||
|
||||
@@ -398,7 +397,7 @@ class ToggleButtonContainer(GridLayout):
|
||||
return self.options[0]
|
||||
|
||||
|
||||
class LabelledTextInput(TextInput):
|
||||
class LabelledTextInput(I18NTextInput):
|
||||
input_property = StringProperty("")
|
||||
multiline = BooleanProperty(False)
|
||||
|
||||
@@ -470,7 +469,7 @@ class LabelledIntInput(LabelledTextInput):
|
||||
|
||||
|
||||
def draw_text(pos, text, **kw):
|
||||
label = CoreLabel(text=text, bold=True, **kw)
|
||||
label = I18NCoreLabel(text=text, bold=True, **kw)
|
||||
label.refresh()
|
||||
Rectangle(texture=label.texture, pos=(pos[0] - label.texture.size[0] / 2, pos[1] - label.texture.size[1] / 2), size=label.texture.size)
|
||||
|
||||
|
||||
Binary file not shown.
@@ -6,6 +6,10 @@ msgstr ""
|
||||
"Content-Type: text/plain; charset=utf-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#. This is the font used, files ONLY relative to 'katrain' directory
|
||||
msgid "Roboto"
|
||||
msgstr "Roboto"
|
||||
|
||||
msgid "Hello World"
|
||||
msgstr "Hello World"
|
||||
|
||||
@@ -18,6 +22,9 @@ msgstr "English"
|
||||
msgid "Dutch"
|
||||
msgstr "Dutch"
|
||||
|
||||
msgid "Korean"
|
||||
msgstr "Korean"
|
||||
|
||||
msgid "pass-button-text"
|
||||
msgstr "Pass"
|
||||
|
||||
@@ -41,12 +48,19 @@ msgstr "Info"
|
||||
msgid "tab:notes"
|
||||
msgstr "Notes"
|
||||
|
||||
msgid 'closedlabel:scoregraph'
|
||||
msgstr 'Score Graph'
|
||||
msgid "closedlabel:scoregraph"
|
||||
msgstr "Score Graph"
|
||||
|
||||
msgid "closedlabel:movestats"
|
||||
msgstr "Move Stats"
|
||||
|
||||
msgid 'closedlabel:movestats'
|
||||
msgstr 'Move Stats'
|
||||
msgid "closedlabel:info¬es"
|
||||
msgstr "Move Info & Notes"
|
||||
|
||||
msgid 'closedlabel:info¬es'
|
||||
msgstr 'Move Info & Notes'
|
||||
msgid "board-pass"
|
||||
msgstr "pass"
|
||||
|
||||
msgid "board-game-end"
|
||||
msgstr ""
|
||||
"game\n"
|
||||
"end"
|
||||
Binary file not shown.
@@ -6,6 +6,10 @@ msgstr ""
|
||||
"Content-Type: text/plain; charset=utf-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#. This is the font used, files ONLY relative to 'katrain' directory
|
||||
msgid "Roboto"
|
||||
msgstr "fonts/NotoSansKR-Regular.otf"
|
||||
|
||||
msgid "Hello World"
|
||||
msgstr "안녕하세요 여러분"
|
||||
|
||||
@@ -15,6 +19,9 @@ msgstr "영어"
|
||||
msgid "Dutch"
|
||||
msgstr "네덜란드어"
|
||||
|
||||
msgid "Korean"
|
||||
msgstr "한국어"
|
||||
|
||||
msgid "pass-button-text"
|
||||
msgstr "페스"
|
||||
|
||||
@@ -57,3 +64,13 @@ msgstr "Score"
|
||||
#. TODO
|
||||
msgid "closedlabel:info¬es"
|
||||
msgstr "Move Info & Notes"
|
||||
|
||||
#. TODO
|
||||
msgid "board-game-end"
|
||||
msgstr ""
|
||||
"게임\n"
|
||||
"끝났다"
|
||||
|
||||
#. TODO
|
||||
msgid "board-pass"
|
||||
msgstr "페스"
|
||||
Binary file not shown.
@@ -6,6 +6,10 @@ msgstr ""
|
||||
"Content-Type: text/plain; charset=utf-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#. This is the font used, files ONLY relative to 'katrain' directory
|
||||
msgid "Roboto"
|
||||
msgstr "Roboto"
|
||||
|
||||
msgid "Hello World"
|
||||
msgstr "Hallo wereld"
|
||||
|
||||
@@ -15,6 +19,9 @@ msgstr "Engels"
|
||||
msgid "Dutch"
|
||||
msgstr "Nederlands"
|
||||
|
||||
msgid "Korean"
|
||||
msgstr "Koreaans"
|
||||
|
||||
msgid "pass-button-text"
|
||||
msgstr "Pas"
|
||||
|
||||
@@ -58,3 +65,13 @@ msgstr "Move Info & Notes"
|
||||
#. TODO
|
||||
msgid "closedlabel:movestats"
|
||||
msgstr "Move Stats"
|
||||
|
||||
#. TODO
|
||||
msgid "board-game-end"
|
||||
msgstr ""
|
||||
"einde\n"
|
||||
"partij"
|
||||
|
||||
#. TODO
|
||||
msgid "board-pass"
|
||||
msgstr "pas"
|
||||
Reference in new issue
Block a user