Replies: 3 comments 11 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.
-
|
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.
-
|
Hello everyone, and thank you for the amazing work on SQLPage! create table if not exists lang2 AS
select 'fr' AS l,
'Bonjour' as __hello,
'Saisir la tâche' as __task,
'Oui' as __yes,
'Non' as __no
union all
select 'en' ,
'Hello' ,
'Type task',
'Yes',
'No'
;
select
'text' as component,
__hello as title,
'Change language : [FR](?l=fr) - [EN](?l=en)
test :
' || __hello ||' - ' || __task
as contents_md
from lang2 where l=IIF(NOT EXISTS (SELECT 1 FROM lang2 where l = $l) ,'fr',$l)
;
SELECT 'form' AS component, 'multipart/form-data' AS enctype;
SELECT
CASE
WHEN $edit IS NOT NULL THEN
(SELECT task FROM todos WHERE id = $edit)
ELSE ''
END AS value,
'task' AS name,
__task AS label,
'text' AS type,
__hello AS placeholder,
TRUE AS autofocus
from lang2 where l=IIF(NOT EXISTS (SELECT 1 FROM lang2 where l = $l) ,'fr',$l)
; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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