Replies: 2 comments 9 replies
-
Hello! There is currently no solution for this that isn't a little verbose. you can use a single CREATE TABLE language (
translation_key VARCHAR(255) PRIMARY KEY,
language_code VARCHAR(5),
translation_value VARCHAR(255)
); Here's an example of querying the translation for "homepage.hello_world" based on the user's language: SELECT l.translation_value
FROM language l
JOIN user u ON l.language_code = u.language_code
WHERE l.translation_key = 'homepage.hello_world' AND u.session_id = sqlpage.cookie('session'); to make this a little less verbose, you can define a function if your database supports stored procedures: -- assuming postgres syntax
CREATE OR REPLACE FUNCTION t(user_id INT, key VARCHAR)
RETURNS VARCHAR AS $$
DECLARE
translation_value VARCHAR;
BEGIN
SELECT l.translation_value INTO translation_value
FROM language l
JOIN user u ON l.language_code = u.language_code
WHERE l.translation_key = key AND u.user_id = user_id;
RETURN translation_value;
END;
$$ LANGUAGE plpgsql; Then use SELECT t($uid, 'homepage.hello_world'); |
Beta Was this translation helpful? Give feedback.
3 replies
-
An idea could be a lookup table and sqlpage function to lookup the table ?
With :
SELECT sqlpage.translate('tl42','en','Hello world')
-- 'Hello world is the default string'. If we have a global settings like 'language', sqlpage could replace the string according to the lookup table. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I was thinking about how SQLPage can handle multilingual support, in the sense that each user can choose the language offered by the application.
I'm somewhat used to working with Java environments, and I know how Bundles work, but... In the case of having to set up SQL queries for the display, I don't see how to do it in a way that you don't have to repeat 20 queries for each tag of the application.
My idea was to make a language table, with a column for each language mapped to the tags column (like a bundle, so to speak). How would you do it?
Beta Was this translation helpful? Give feedback.
All reactions