Skip to content

Commit

Permalink
localization rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed May 4, 2024
1 parent eab6312 commit 9dec874
Show file tree
Hide file tree
Showing 42 changed files with 153 additions and 184 deletions.
6 changes: 3 additions & 3 deletions data/cage-tests/gui/gui.assets
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ scheme = texture
skin.png

[]
scheme = textpack
utf8test.textpack
texts.textpack
scheme = texts
multilingual = false
texts.po

[]
scheme = texture
Expand Down
3 changes: 1 addition & 2 deletions data/cage-tests/gui/gui.pack
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ english.png
immortal.ttf
roboto.ttf
skin.png
texts.textpack
utf8test.textpack
texts.po
/cage/font/ubuntu/regular.ttf
/cage/font/ubuntu/bold.ttf
/cage/font/ubuntu/italic.ttf
Expand Down
2 changes: 2 additions & 0 deletions data/cage-tests/gui/texts.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
msgid "texts/hello"
msgstr "hello world"
2 changes: 0 additions & 2 deletions data/cage-tests/gui/texts.textpack

This file was deleted.

Binary file removed data/cage-tests/gui/utf8test.textpack
Binary file not shown.
9 changes: 0 additions & 9 deletions data/cage-tests/texts/czech.textpack

This file was deleted.

9 changes: 0 additions & 9 deletions data/cage-tests/texts/english.textpack

This file was deleted.

6 changes: 2 additions & 4 deletions data/cage-tests/texts/texts.assets
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ scheme = pack
texts.pack

[]
scheme = textpack
alias = texts.textpack
czech.textpack
english.textpack
scheme = texts
texts.pot

[]
scheme = texture
Expand Down
11 changes: 11 additions & 0 deletions data/cage-tests/texts/texts.cs_CZ.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
msgid "short"
msgstr "ahoj"

msgid "long/a"
msgstr "příliš žluťoučký kůň úpěl ďábelské ódy"

msgid "long/b"
msgstr "lorem ipsum dolor sit amet"

msgid "params"
msgstr "pozice: x: {0}, y: {1}, z: {2}"
11 changes: 11 additions & 0 deletions data/cage-tests/texts/texts.en_US.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
msgid "short"
msgstr "hello"

msgid "long/a"
msgstr "brown fox jumps over a lazy dog"

msgid "long/b"
msgstr "lorem ipsum dolor sit amet"

msgid "params"
msgstr "position: x: {0}, y: {1}, z: {2}"
4 changes: 1 addition & 3 deletions data/cage-tests/texts/texts.pack
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
../gui/gui.pack

[]
texts.pot
czech.png
english.png

[]
czech.textpack
11 changes: 11 additions & 0 deletions data/cage-tests/texts/texts.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
msgid "short"
msgstr "hello"

msgid "long/a"
msgstr "brown_fox_jumps_over_a_lazy_dog"

msgid "long/b"
msgstr "lorem_ipsum"

msgid "params"
msgstr "position: xyz"
2 changes: 1 addition & 1 deletion externals/cage
Submodule cage updated 34 files
+0 −3 schemes/textpack.scheme
+8 −0 schemes/texts.scheme
+2 −7 sources/asset-database/databank.cpp
+0 −2 sources/asset-database/database.h
+0 −27 sources/asset-database/processing.cpp
+0 −10 sources/asset-database/scheme.cpp
+3 −11 sources/asset-processor/main.cpp
+1 −1 sources/asset-processor/processor.h
+0 −55 sources/asset-processor/textPack.cpp
+150 −0 sources/asset-processor/texts.cpp
+1 −2 sources/include/cage-core/assetContext.h
+2 −2 sources/include/cage-core/assetHeader.h
+6 −6 sources/include/cage-core/assetManager.h
+0 −34 sources/include/cage-core/textPack.h
+44 −0 sources/include/cage-core/texts.h
+3 −3 sources/include/cage-engine/guiBuilder.h
+3 −4 sources/include/cage-engine/guiComponents.h
+2 −3 sources/include/cage-engine/scene.h
+18 −32 sources/libcore/assets/assetManager.cpp
+0 −45 sources/libcore/assets/assetStructs.cpp
+290 −0 sources/libcore/assets/texts.cpp
+0 −119 sources/libcore/textPack.cpp
+1 −1 sources/libengine/assets/font.cpp
+1 −1 sources/libengine/assets/model.cpp
+1 −1 sources/libengine/assets/renderObject.cpp
+1 −1 sources/libengine/assets/shaderProgram.cpp
+1 −1 sources/libengine/assets/sound.cpp
+1 −1 sources/libengine/assets/texture.cpp
+2 −2 sources/libengine/graphics/renderPipeline.cpp
+2 −2 sources/libengine/gui/guiBuilder.cpp
+2 −2 sources/libengine/gui/items.cpp
+2 −2 sources/libsimple/gameloop.cpp
+2 −25 sources/test-core/assetManager.cpp
+15 −0 sources/test-core/strings.cpp
8 changes: 4 additions & 4 deletions sources/engine/rawWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using namespace cage;

bool closing = false;
constexpr uint32 assetsName = HashString("cage-tests/logo/logo.pack");
constexpr uint32 AssetsName = HashString("cage-tests/logo/logo.pack");

int main(int argc, char *args[])
{
Expand All @@ -45,10 +45,10 @@ int main(int argc, char *args[])
assets->defineScheme<AssetSchemeIndexSound, Sound>(genAssetSchemeSound());

// load assets
assets->load(assetsName);
assets->load(AssetsName);
while (true)
{
if (assets->get<AssetSchemeIndexPack, AssetPack>(assetsName))
if (assets->get<AssetSchemeIndexPack, AssetPack>(AssetsName))
break;
assets->processCustomThread(0);
threadSleep(1000);
Expand Down Expand Up @@ -92,7 +92,7 @@ int main(int argc, char *args[])
}

// unload assets
assets->unload(assetsName);
assets->unload(AssetsName);
assets->unloadCustomThread(0);

return 0;
Expand Down
6 changes: 3 additions & 3 deletions sources/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ namespace GuiTestClassNS

// run
initialize();
static constexpr uint32 assetsName = HashString("cage-tests/gui/gui.pack");
engineAssets()->load(assetsName);
static constexpr uint32 AssetsName = HashString("cage-tests/gui/gui.pack");
engineAssets()->load(AssetsName);
engineRun();
engineAssets()->unload(assetsName);
engineAssets()->unload(AssetsName);
engineFinalize();

return 0;
Expand Down
14 changes: 7 additions & 7 deletions sources/gui/texts/fontLineSpacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace cage;

const char *fontNames[] = {
const char *FontNames[] = {
"cage-tests/gui/DroidSansMono.ttf",
"cage-tests/gui/immortal.ttf",
"cage-tests/gui/roboto.ttf",
Expand All @@ -14,7 +14,7 @@ const char *fontNames[] = {
"cage/font/ubuntu/italic.ttf",
"cage/font/ubuntu/monospace.ttf",
};
const String labelTexts[] = {
const String LabelTexts[] = {
"Droid Sans Mono",
"Immortal",
"Roboto",
Expand All @@ -26,8 +26,8 @@ const String labelTexts[] = {
};
const String multilineText = "lorem ipsum dolor sit amet\npříliš žluťoučký kůň úpěl ďábelské ódy\na quick brown fox jumps over a lazy dog\n\nhello world, foo, bar, baz";

const uint32 fontsCount = sizeof(fontNames) / sizeof(fontNames[0]);
static_assert(sizeof(fontNames) / sizeof(fontNames[0]) == sizeof(labelTexts) / sizeof(labelTexts[0]), "arrays must have same number of elements");
const uint32 fontsCount = sizeof(FontNames) / sizeof(FontNames[0]);
static_assert(sizeof(FontNames) / sizeof(FontNames[0]) == sizeof(LabelTexts) / sizeof(LabelTexts[0]), "arrays must have same number of elements");

class GuiTestImpl : public GuiTestClass
{
Expand Down Expand Up @@ -64,8 +64,8 @@ class GuiTestImpl : public GuiTestClass
e->value<GuiParentComponent>().parent = 2;
e->value<GuiParentComponent>().order = i * 3 + 0;
e->value<GuiLabelComponent>();
e->value<GuiTextComponent>().value = labelTexts[i];
e->value<GuiTextFormatComponent>().font = HashString(fontNames[i]);
e->value<GuiTextComponent>().value = LabelTexts[i];
e->value<GuiTextFormatComponent>().font = HashString(FontNames[i]);
}

{
Expand All @@ -80,7 +80,7 @@ class GuiTestImpl : public GuiTestClass
e->value<GuiParentComponent>().parent = 1000 + i;
e->value<GuiLabelComponent>();
e->value<GuiTextComponent>().value = multilineText;
e->value<GuiTextFormatComponent>().font = HashString(fontNames[i]);
e->value<GuiTextFormatComponent>().font = HashString(FontNames[i]);
}

{
Expand Down
12 changes: 6 additions & 6 deletions sources/gui/texts/fontScaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace cage;

const char *fontNames[] = {
const char *FontNames[] = {
"cage-tests/gui/DroidSansMono.ttf",
"cage-tests/gui/immortal.ttf",
"cage-tests/gui/roboto.ttf",
Expand All @@ -14,7 +14,7 @@ const char *fontNames[] = {
"cage/font/ubuntu/italic.ttf",
"cage/font/ubuntu/monospace.ttf",
};
const String labelTexts[] = {
const String LabelTexts[] = {
"Droid Sans Mono",
"Immortal",
"Roboto",
Expand All @@ -25,8 +25,8 @@ const String labelTexts[] = {
"Ubuntu Mono",
};

const uint32 fontsCount = sizeof(fontNames) / sizeof(fontNames[0]);
static_assert(sizeof(fontNames) / sizeof(fontNames[0]) == sizeof(labelTexts) / sizeof(labelTexts[0]), "arrays must have same number of elements");
const uint32 fontsCount = sizeof(FontNames) / sizeof(FontNames[0]);
static_assert(sizeof(FontNames) / sizeof(FontNames[0]) == sizeof(LabelTexts) / sizeof(LabelTexts[0]), "arrays must have same number of elements");

class GuiTestImpl : public GuiTestClass
{
Expand Down Expand Up @@ -61,9 +61,9 @@ class GuiTestImpl : public GuiTestClass
e->value<GuiParentComponent>().parent = 2;
e->value<GuiParentComponent>().order = i;
e->value<GuiLabelComponent>();
e->value<GuiTextComponent>().value = labelTexts[i];
e->value<GuiTextComponent>().value = LabelTexts[i];
GuiTextFormatComponent &format = e->value<GuiTextFormatComponent>();
format.font = HashString(fontNames[i]);
format.font = HashString(FontNames[i]);
format.align = TextAlignEnum::Center;
format.color = colorHsvToRgb(Vec3(randomChance(), 1, 1));
}
Expand Down
12 changes: 6 additions & 6 deletions sources/gui/texts/fontSizes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using namespace cage;

constexpr const char *fontNames[] = {
constexpr const char *FontNames[] = {
"cage-tests/gui/DroidSansMono.ttf",
"cage-tests/gui/immortal.ttf",
"cage-tests/gui/roboto.ttf",
Expand All @@ -12,7 +12,7 @@ constexpr const char *fontNames[] = {
"cage/font/ubuntu/italic.ttf",
"cage/font/ubuntu/monospace.ttf",
};
constexpr String labelTexts[] = {
constexpr String LabelTexts[] = {
"Droid Sans Mono",
"Immortal",
"Roboto",
Expand All @@ -24,8 +24,8 @@ constexpr String labelTexts[] = {
};
constexpr String multilineText = "lorem ipsum dolor sit amet\npříliš žluťoučký kůň úpěl ďábelské ódy\na quick brown fox jumps over a lazy dog\nhello world, foo, bar, baz\n\n";

const uint32 fontsCount = array_size(fontNames);
static_assert(array_size(fontNames) == array_size(labelTexts));
const uint32 fontsCount = array_size(FontNames);
static_assert(array_size(FontNames) == array_size(LabelTexts));

constexpr Real fontSizes[] = { 9, 11, 14, 18 };

Expand All @@ -46,11 +46,11 @@ class GuiTestImpl : public GuiTestClass
}
for (uint32 fontIndex = 0; fontIndex < fontsCount; fontIndex++)
{
g->label().text(labelTexts[fontIndex]);
g->label().text(LabelTexts[fontIndex]);
for (Real size : fontSizes)
{
GuiTextFormatComponent f;
f.font = HashString(fontNames[fontIndex]);
f.font = HashString(FontNames[fontIndex]);
f.size = size;
g->label().text(multilineText).textFormat(f);
}
Expand Down
14 changes: 7 additions & 7 deletions sources/gui/texts/fontTypography.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using namespace cage;

const char *fontNames[] = {
const char *FontNames[] = {
"cage-tests/gui/DroidSansMono.ttf",
"cage-tests/gui/immortal.ttf",
"cage-tests/gui/roboto.ttf",
Expand All @@ -12,7 +12,7 @@ const char *fontNames[] = {
"cage/font/ubuntu/italic.ttf",
"cage/font/ubuntu/monospace.ttf",
};
const String labelTexts[] = {
const String LabelTexts[] = {
"Droid Sans Mono",
"Immortal",
"Roboto",
Expand All @@ -24,8 +24,8 @@ const String labelTexts[] = {
};
const String multilineText = "lorem ipsum dolor sit amet\npříliš žluťoučký kůň úpěl ďábelské ódy\na quick brown fox jumps over a lazy dog\n\nhello world, foo, bar, baz";

const uint32 fontsCount = sizeof(fontNames) / sizeof(fontNames[0]);
static_assert(sizeof(fontNames) / sizeof(fontNames[0]) == sizeof(labelTexts) / sizeof(labelTexts[0]), "arrays must have same number of elements");
const uint32 fontsCount = sizeof(FontNames) / sizeof(FontNames[0]);
static_assert(sizeof(FontNames) / sizeof(FontNames[0]) == sizeof(LabelTexts) / sizeof(LabelTexts[0]), "arrays must have same number of elements");

class GuiTestImpl : public GuiTestClass
{
Expand All @@ -49,8 +49,8 @@ class GuiTestImpl : public GuiTestClass
e->value<GuiParentComponent>().parent = 2;
e->value<GuiParentComponent>().order = i * 2 + 0;
e->value<GuiLabelComponent>();
e->value<GuiTextComponent>().value = labelTexts[i];
e->value<GuiTextFormatComponent>().font = HashString(fontNames[i]);
e->value<GuiTextComponent>().value = LabelTexts[i];
e->value<GuiTextFormatComponent>().font = HashString(FontNames[i]);
}

{
Expand All @@ -65,7 +65,7 @@ class GuiTestImpl : public GuiTestClass
e->value<GuiParentComponent>().parent = 1000 + i;
e->value<GuiLabelComponent>();
e->value<GuiTextComponent>().value = multilineText;
e->value<GuiTextFormatComponent>().font = HashString(fontNames[i]);
e->value<GuiTextFormatComponent>().font = HashString(FontNames[i]);
}
}
}
Expand Down
42 changes: 0 additions & 42 deletions sources/gui/texts/utf8test.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion sources/gui/widgets/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GuiTestImpl : public GuiTestClass
p.order = index++;
e->value<GuiLabelComponent>();
e->value<GuiTextComponent>().value = "hover over this";
e->value<GuiTooltipComponent>().tooltip = detail::guiTooltipText<"", HashString("cage-tests/gui/texts.textpack"), HashString("texts/hello")>();
e->value<GuiTooltipComponent>().tooltip = detail::guiTooltipText<"", HashString("texts/hello")>();
}

{ // horizontal
Expand Down
Loading

0 comments on commit 9dec874

Please sign in to comment.