trongate / trongate-framework

The Trongate PHP framework
https://trongate.io
Other
1.11k stars 100 forks source link

Localization #189

Closed sasin91 closed 1 month ago

sasin91 commented 2 months ago

Skærmbillede 2024-07-10 174218 Skærmbillede 2024-07-10 180640 Skærmbillede 2024-07-10 215705

Provides translation support both in JS (tested in trongate_pages) & in PHP for templates. The current implementation stores the translations in a json file for each language, if desired i can implement support for multiple or a different storage, eg. DB.

modules/trongate_localization/assets/lang/en.json

{
    "Hello": "Howdy Trongate",
}

in JS

t("Hello", "fallback", "en") // Howdy Trongate
t("Something", "fallback", "en") // fallback
t("My little beauties") // My little beauties

in a PHP

<?= t("Hello") ?> // Howdy trongate
<?= money(100") ?> // 100.0$

I have also made a little groundwork to support currency and money formatting, but not quite sure how to implement on trongate-pages.

Currently if a locale is not provided it tries to infer it from the "ACCEPT-LANGUAGE" header, this can ofcourse be changed to support others, eg. ?language=da query string :)

sasin91 commented 2 months ago

Noticed trongate-mx offers mx-build-modal html attr. Should i update the translate modal to leverage that, once it's released? 😊

sasin91 commented 2 months ago

Skærmbillede 2024-07-13 160627 in c2ce4a3

sasin91 commented 2 months ago

Starting to get a bit complicated with the Drivers and i feel like Database is probably the better place to store the translations tbh. Got the JSON file idea from api.json & frontend frameworks. :)

trongate commented 1 month ago

I love what you've done! It's very easy for me to see that you're an outstanding developer and, quite frankly, you probably know more about this side of things than I do.

However, just to give you a heads up:

Localization (i.e., getting Trongate to work with multiple languages) is one of the absolute top priorities for the framework. This is something that I consider to be extremely important. I want it. We need it.

Between now and November, we're working flat out on improving the documentation and also rebuilding Trongate MX and Trongate Pages. This is a HUGE job and it's taking all of our attention. So, what I'm going to say is that I love what you're doing. However, I think you're a little bit too early to the party with this.

Let me assure you, we are going to be adding localization functionality into Trongate, but that won't be until the completion of the other things that we're doing. I predict that we'll be moving onto localization sometime between November and January. I know that's a long time, but we have to do this right. We are building tools that will hopefully last for decades.

When the time comes, I hope you'll be able to give us your input and help us to make Trongate a beautiful multilingual framework.

Hail Sasin91!

sasin91 commented 1 month ago

I had a feeling this would be the case. :)

I'm totally fine leaving this as a draft and later checking it out to see which ideas sticks and which to ditch :)