Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Internationalization #619

Open
maekoos opened this issue Sep 23, 2024 · 1 comment
Open

Feature request: Internationalization #619

maekoos opened this issue Sep 23, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@maekoos
Copy link

maekoos commented Sep 23, 2024

It would be really nice to have sqlpage handle internationalization for us. Maybe using a cookie for switching between languages and fallback to Accept-Language, and a json file in sqlpage directory for adding translations for each locale.

Right now the only option would be to use a (temporary?) table or write a function for handling this, which would require manually reading from the headers and cookies for every single text on the web page.

I'm thinking something like this:

SELECT 'text' AS component, sqlpage.i18n('home_title') as title;
{
  "en": { "home_title": "Welcome!" },
  "sv": { "home_title": "Välkommen!" }
}

Wouldn't be too hard to implement and should be sufficient for pretty much all applications.

@maekoos maekoos added the enhancement New feature or request label Sep 23, 2024
@lovasoa
Copy link
Collaborator

lovasoa commented Nov 13, 2024

Hi !
Here is a link to a previous discussion on this topic: #248
I am not excluding implementing the solution described in this feature request in the future, but the current recommended solution is to handle internationalization directly in the database, by defining your own custom localized message fetching logic.

An example of what this could look like is:

SET lang = sqlpage.cookie('lang');

select 'hero' as component, t($lang, 'home_title') as title;

with a translation function defined like this (postgresql example):

CREATE OR REPLACE FUNCTION t(language VARCHAR(5), key VARCHAR(255))
RETURNS VARCHAR(255) AS $$
DECLARE
    result VARCHAR(255);
BEGIN
    SELECT translation_value INTO result
    FROM language
    WHERE language_code = language AND translation_key = key;
    RETURN result;
END;
$$ LANGUAGE plpgsql;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants