L10N Language support

FossilOrigin-Name: 14aa65bba9ad19568fcec029c2edd8e8e7ea2c0a78a019265c2ff0c8d639ff80
This commit is contained in:
nekobit 2022-06-05 22:25:18 +00:00
parent 8382573d30
commit c5d8b9df68
25 changed files with 133 additions and 26 deletions

4
dist/js/main.js vendored
View file

@ -2,6 +2,8 @@ Element.prototype.insertAfter = function(element) {
element.parentNode.insertBefore(this, element.nextSibling);
};
function construct_quick_reply_form(replyid)
{
let src = document.createElement("form");
@ -88,6 +90,6 @@ function create_reply_form(e)
for (let i = 0; i < reply_btn.length; ++i)
{
reply_btn[i].onclick = create_reply_form;
reply_btn[i].addEventListener('click', create_reply_form);
}
})();

View file

@ -13,6 +13,7 @@
RewriteEngine on
RewriteRule ^/(.*).css$ /$1.css [L]
RewriteRule ^/svg/(.*).svg$ /svg/$1.svg [L]
RewriteRule ^/js/(.*).js /svg/$1.js [L]
RewriteRule ^/(treebird\_logo|favicon).png$ /$1.png [L]
# Set PATH_INFO variable

View file

@ -26,7 +26,6 @@ void content_about(struct session* ssn, mastodont_t* api, char** data)
{
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = data_about,
.sidebar_left = NULL
};
@ -40,7 +39,6 @@ void content_about_license(struct session* ssn, mastodont_t* api, char** data)
{
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = data_license,
.sidebar_left = NULL
};

View file

@ -192,7 +192,8 @@ static void fetch_account_page(struct session* ssn,
data = callback(ssn, api,
&acct, args);
account_page = load_account_page(api,
account_page = load_account_page(ssn,
api,
&acct,
relationships,
tab,
@ -206,7 +207,6 @@ static void fetch_account_page(struct session* ssn,
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = account_page,
.sidebar_left = NULL
};
@ -366,7 +366,8 @@ char* construct_accounts(mastodont_t* api,
return construct_func_strings(construct_account_voidwrap, &acct_args, size, ret_size);
}
char* load_account_page(mastodont_t* api,
char* load_account_page(struct session* ssn,
mastodont_t* api,
struct mstdnt_account* acct,
struct mstdnt_relationship* relationship,
enum account_tab tab,
@ -376,7 +377,7 @@ char* load_account_page(mastodont_t* api,
size_t size;
char* result;
struct account_page page = {
.locale = L10N_EN_US,
.locale = l10n_normalize(ssn->config.lang),
.account = acct,
.header_image = acct->header,
.profile_image = acct->avatar,
@ -538,7 +539,6 @@ void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** dat
struct base_page b = {
.category = BASE_CAT_BOOKMARKS,
.locale = L10N_EN_US,
.content = output,
.sidebar_left = NULL
};
@ -601,7 +601,6 @@ void content_account_favourites(struct session* ssn, mastodont_t* api, char** da
struct base_page b = {
.category = BASE_CAT_FAVOURITES,
.locale = L10N_EN_US,
.content = output,
.sidebar_left = NULL
};

View file

@ -68,7 +68,8 @@ char* construct_accounts(mastodont_t* api,
size_t construct_account_page(char** result, struct account_page* page, char* content);
char* load_account_page(mastodont_t* api,
char* load_account_page(struct session* ssn,
mastodont_t* api,
struct mstdnt_account* acct,
struct mstdnt_relationship* relationship,
enum account_tab tab,

View file

@ -38,7 +38,7 @@
void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* api)
{
char* cookie = getenv("HTTP_COOKIE");
enum l10n_locale locale = page->locale;
enum l10n_locale locale = l10n_normalize(ssn->config.lang);
const char* login_string = "<a href=\"login\" id=\"login-header\">Login / Register</a>";
const char* sidebar_embed = "<iframe class=\"sidebar-frame\" src=\"/notifications_compact\"></iframe>";
char* background_url_css = NULL;

View file

@ -40,7 +40,6 @@ enum base_category
struct base_page
{
enum base_category category;
enum l10n_locale locale;
char* content;
char* sidebar_left;
};

View file

@ -52,6 +52,7 @@ char* read_cookies_env(struct cookie_values* cookies)
{ "access_token", &(cookies->access_token), key_string },
{ "logged_in", &(cookies->logged_in), key_string },
{ "theme", &(cookies->theme), key_string },
{ "lang", &(cookies->lang), key_int },
{ "instance_url", &(cookies->instance_url), key_string },
{ "background_url", &(cookies->background_url), key_string },
{ "client_id", &(cookies->client_id), key_string },

View file

@ -26,6 +26,7 @@ struct cookie_values
struct key access_token;
struct key logged_in;
struct key theme;
struct key lang;
struct key instance_url;
struct key background_url;
struct key client_id;

View file

@ -57,7 +57,6 @@ void content_not_found(struct session* ssn, mastodont_t* api, char* path)
page = tmpl_gen_error_404(&data, NULL);
struct base_page b = {
.locale = L10N_EN_US,
.content = page,
.sidebar_left = NULL
};

View file

@ -23,8 +23,12 @@ enum l10n_locale
{
L10N_EN_US = 0,
L10N_ES_ES,
L10N_CH_TW,
L10N_LOCALE_LEN,
};
#define l10n_normalize(index) ((index) < L10N_LOCALE_LEN && (index) >= 0 ? (index) : 0)
enum l10n_string
{
/* GENERAL */
@ -318,6 +322,103 @@ static const char* const L10N[][_L10N_LEN] = {
"follows?",
"poll",
},
// CH_TW
{
/* GENERAL */
"Treebird", // L10N_APP_NAME
"首頁",
"本地",
"聯邦",
"通知",
"清單",
"我的最愛",
"書籤",
"私訊",
"設定",
"搜尋",
"搜尋",
/* CONFIG */
"一般",
"帳號",
"JavaScript",
"快速動作 - 在背景執行讚、助推等動作",
"快速回覆 - 回覆不需重定向",
"即時動態 - 即時獲取動態,不需重新載入",
"外觀",
"主題選擇",
"Treebird 2.0 - 預設,簡約主題",
"Treebird 3.0 - 扁平化,摩登主題",
"配色方案",
"淺色",
"深色",
"儲存",
/* ACCOUNT */
"選單",
"訂閱",
"取消訂閱",
"封鎖",
"解除封鎖",
"靜音",
"解除靜音",
"狀態",
"追隨中",
"追隨者",
"塗鴉",
"媒體",
"置頂",
"在追隨你!",
"追隨",
"等待批准追隨請求",
"追隨中!",
"你被這個使用者封鎖了。",
/* STATUS */
"回覆",
"助推",
"",
"快速",
"檢視",
"回覆",
/* ERRORS */
"找不到內容",
"找不到狀態",
"找不到帳號",
/* VISIBILITIES */
"公開",
"首頁",
"私密",
"私訊",
"本地",
/* LOGIN */
"登入",
"註冊",
"使用者名稱",
"密碼",
"登入",
"登入 / 註冊",
"無法登入",
/* NOTIFICATIONS */
"讚了你的動態",
"反應了",
"助推了你的動態",
"追隨了你",
"想要追隨你",
"投票結果",
"讚了",
"反應了",
"助推了",
"跟隨了",
"跟隨嗎?",
"投票",
}
};
#endif // TREEBIRD_L10N_H

View file

@ -81,7 +81,6 @@ void content_lists(struct session* ssn, mastodont_t* api, char** data)
struct base_page b = {
.category = BASE_CAT_LISTS,
.locale = L10N_EN_US,
.content = lists_page,
.sidebar_left = NULL
};

View file

@ -25,6 +25,7 @@ struct local_config
char* logged_in;
char* theme;
char* background_url;
int lang;
int themeclr;
int jsactions;
int jsreply;

View file

@ -95,4 +95,5 @@ void load_config(struct session* ssn, mastodont_t* api)
set_config_int(LOAD_CFG_SIM("instanceshowshoutbox", instance_show_shoutbox));
set_config_int(LOAD_CFG_SIM("instancepanel", instance_panel));
set_config_int(LOAD_CFG_SIM("notifembed", notif_embed));
set_config_int(LOAD_CFG_SIM("lang", lang));
}

View file

@ -207,7 +207,6 @@ void content_login(struct session* ssn, mastodont_t* api, char** data)
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = page,
.sidebar_left = NULL
};

View file

@ -107,6 +107,7 @@ int main(void)
.config = {
.theme = "treebird20",
.themeclr = 0,
.lang = L10N_EN_US,
.jsactions = 1,
.jsreply = 1,
.jslive = 0,

View file

@ -223,7 +223,6 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data)
struct base_page b = {
.category = BASE_CAT_NOTIFICATIONS,
.locale = L10N_EN_US,
.content = page,
.sidebar_left = NULL
};

View file

@ -83,7 +83,6 @@ void content_config_general(struct session* ssn, mastodont_t* api, char** data)
struct base_page b = {
.category = BASE_CAT_CONFIG,
.locale = L10N_EN_US,
.content = general_page,
.sidebar_left = sidebar_html
};
@ -101,7 +100,6 @@ void content_config_appearance(struct session* ssn, mastodont_t* api, char** dat
struct base_page b = {
.category = BASE_CAT_CONFIG,
.locale = L10N_EN_US,
.content = data_config_appearance,
.sidebar_left = sidebar_html
};

View file

@ -87,6 +87,7 @@ char* read_post_data(struct post_values* post)
struct key_value_refs refs[] = {
{ "set", &(post->set), key_int },
{ "content", &(post->content), key_string },
{ "lang", &(post->lang), key_int },
{ "itype", &(post->itype), key_string },
{ "id", &(post->id), key_string },
{ "theme", &(post->theme), key_string },

View file

@ -33,6 +33,7 @@ struct post_values
// Config
struct key theme; // String
struct key themeclr; // Int
struct key lang; // Int
struct key jsactions; // Int
struct key jsreply; // Int
struct key jslive; // Int

View file

@ -49,7 +49,6 @@ void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, cha
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = out_data,
.sidebar_left = NULL
};

View file

@ -744,7 +744,6 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = output,
.sidebar_left = NULL
};

View file

@ -70,7 +70,6 @@ void content_test(struct session* ssn, mastodont_t* api, char** data)
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = page,
.sidebar_left = NULL
};

View file

@ -85,7 +85,6 @@ void tl_home(struct session* ssn, mastodont_t* api, int local)
struct base_page b = {
.category = BASE_CAT_HOME,
.locale = L10N_EN_US,
.content = output,
.sidebar_left = NULL
};
@ -154,7 +153,6 @@ void tl_direct(struct session* ssn, mastodont_t* api)
struct base_page b = {
.category = BASE_CAT_DIRECT,
.locale = L10N_EN_US,
.content = output,
.sidebar_left = NULL
};
@ -224,7 +222,6 @@ void tl_public(struct session* ssn, mastodont_t* api, int local, enum base_categ
struct base_page b = {
.category = cat,
.locale = L10N_EN_US,
.content = output,
.sidebar_left = NULL
};
@ -287,7 +284,6 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
struct base_page b = {
.category = BASE_CAT_LISTS,
.locale = L10N_EN_US,
.content = output,
.sidebar_left = NULL
};
@ -350,7 +346,6 @@ void tl_tag(struct session* ssn, mastodont_t* api, char* tag_id)
struct base_page b = {
.category = BASE_CAT_NONE,
.locale = L10N_EN_US,
.content = output,
.sidebar_left = NULL
};

View file

@ -2,8 +2,21 @@
<form action="general" method="post">
<!-- Lets server know we sent it -->
<input type="hidden" name="set" value="1">
<h1>General</h1>
<input class="btn btn-single" type="submit" value="Save">
<h3>Locales</h3>
<ul>
<li>
<label for="cfglang">Language:</label>
<select name="lang" id="cfglang">
<option value="0">English</option>
<option value="1">Spanish</option>
<option value="2">Chinese (Traditional)</option>
</select>
</li>
</ul>
<h3>JavaScript</h3>
<ul>
<li>