Moving i18n to sepparate module

This commit is contained in:
Franz Dietrich 2021-08-13 10:53:33 +02:00
parent be95cf68fc
commit 039a2b5e23
9 changed files with 44 additions and 7 deletions

11
Cargo.lock generated
View File

@ -2759,6 +2759,7 @@ dependencies = [
"enum-map", "enum-map",
"fluent 0.15.0", "fluent 0.15.0",
"image", "image",
"pslink-locales",
"pslink-shared", "pslink-shared",
"qrcode", "qrcode",
"seed", "seed",
@ -2769,6 +2770,16 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "pslink-locales"
version = "0.4.1-beta.2"
dependencies = [
"fluent 0.15.0",
"pslink-shared",
"serde",
"unic-langid",
]
[[package]] [[package]]
name = "pslink-shared" name = "pslink-shared"
version = "0.4.1-beta.2" version = "0.4.1-beta.2"

View File

@ -1,5 +1,7 @@
[workspace] [workspace]
members = [ members = [
"shared",
"locales",
"pslink", "pslink",
"app", "app",
] ]

View File

@ -27,6 +27,7 @@ qrcode = "0.12"
image = "0.23" image = "0.23"
pslink-shared = { version="0.4.1-alpha.0", path = "../shared" } pslink-shared = { version="0.4.1-alpha.0", path = "../shared" }
pslink-locales = { version="0.4.1-alpha.0", path = "../locales" }
[dependencies.web-sys] [dependencies.web-sys]
version = "0.3" version = "0.3"

View File

@ -1,5 +1,4 @@
//! The admin interface of pslink. It communicates with the server mostly via https and json. //! The admin interface of pslink. It communicates with the server mostly via https and json.
pub mod i18n;
pub mod navigation; pub mod navigation;
pub mod pages; pub mod pages;
@ -13,7 +12,7 @@ use seed::window;
use seed::IF; use seed::IF;
use seed::{attrs, button, div, input, label, log, prelude::*, App, Url, C}; use seed::{attrs, button, div, input, label, log, prelude::*, App, Url, C};
use crate::i18n::I18n; use pslink_locales::I18n;
// ------ ------ // ------ ------
// Init // Init
@ -45,7 +44,7 @@ struct Model {
index: usize, index: usize,
location: Location, location: Location,
page: Page, page: Page,
i18n: i18n::I18n, i18n: I18n,
user: Loadable<User>, user: Loadable<User>,
login_form: LoginForm, login_form: LoginForm,
login_data: LoginUser, login_data: LoginUser,

View File

@ -1,12 +1,13 @@
//! Create the top menu of the app //! Create the top menu of the app
use fluent::fluent_args; use fluent::fluent_args;
use pslink_locales::I18n;
use pslink_shared::{ use pslink_shared::{
apirequests::users::Role, apirequests::users::Role,
datatypes::{Lang, User}, datatypes::{Lang, User},
}; };
use seed::{a, attrs, div, li, nav, nodes, ol, prelude::*, Url, C}; use seed::{a, attrs, div, li, nav, nodes, ol, prelude::*, Url, C};
use crate::{i18n::I18n, Msg}; use crate::Msg;
/// Generate the top navigation menu of all pages. /// Generate the top navigation menu of all pages.
/// ///

View File

@ -4,6 +4,7 @@ use std::ops::Deref;
use enum_map::EnumMap; use enum_map::EnumMap;
use fluent::fluent_args; use fluent::fluent_args;
use image::{DynamicImage, ImageOutputFormat, Luma}; use image::{DynamicImage, ImageOutputFormat, Luma};
use pslink_locales::I18n;
use qrcode::{render::svg, QrCode}; use qrcode::{render::svg, QrCode};
use seed::{ use seed::{
a, attrs, div, h1, img, input, log, nodes, prelude::*, raw, section, span, table, td, th, tr, a, attrs, div, h1, img, input, log, nodes, prelude::*, raw, section, span, table, td, th, tr,
@ -20,7 +21,7 @@ use pslink_shared::{
datatypes::{FullLink, Lang, Loadable, User}, datatypes::{FullLink, Lang, Loadable, User},
}; };
use crate::{get_host, i18n::I18n, unwrap_or_return}; use crate::{get_host, unwrap_or_return};
/// Setup the page /// Setup the page
pub fn init(mut url: Url, orders: &mut impl Orders<Msg>, i18n: I18n) -> Model { pub fn init(mut url: Url, orders: &mut impl Orders<Msg>, i18n: I18n) -> Model {

View File

@ -1,6 +1,7 @@
//! List all users in case an admin views it, list the "self" user otherwise. //! List all users in case an admin views it, list the "self" user otherwise.
use enum_map::EnumMap; use enum_map::EnumMap;
use pslink_locales::I18n;
use pslink_shared::{ use pslink_shared::{
apirequests::general::{Operation, Ordering}, apirequests::general::{Operation, Ordering},
apirequests::{ apirequests::{
@ -13,7 +14,7 @@ use seed::{a, attrs, div, h1, input, log, p, prelude::*, section, table, td, th,
/* /*
* init * init
*/ */
use crate::{i18n::I18n, unwrap_or_return}; use crate::unwrap_or_return;
#[must_use] #[must_use]
pub fn init(mut url: Url, orders: &mut impl Orders<Msg>, i18n: I18n) -> Model { pub fn init(mut url: Url, orders: &mut impl Orders<Msg>, i18n: I18n) -> Model {
orders.send_msg(Msg::Query(UserQueryMsg::Fetch)); orders.send_msg(Msg::Query(UserQueryMsg::Fetch));

21
locales/Cargo.toml Normal file
View File

@ -0,0 +1,21 @@
[package]
name = "pslink-locales"
authors = ["Dietrich <dietrich@teilgedanken.de>"]
categories = ["web-programming", "network-programming", "web-programming::http-server", "command-line-utilities"]
description = "The translation strings for pslink"
edition = "2018"
keywords = ["url", "link", "webpage", "actix", "web"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/enaut/pslink/"
version = "0.4.1-beta.2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
fluent = "0.15"
serde = {version="1.0", features = ["derive"]}
unic-langid = "0.9"
pslink-shared = { version="0.4.1-alpha.0", path = "../shared" }

View File

@ -68,7 +68,7 @@ impl I18n {
pub const fn ftl_messages(lang: Lang) -> &'static str { pub const fn ftl_messages(lang: Lang) -> &'static str {
macro_rules! include_ftl_messages { macro_rules! include_ftl_messages {
( $lang_id:literal ) => { ( $lang_id:literal ) => {
include_str!(concat!("../../locales/", $lang_id, "/main.ftl")) include_str!(concat!("../", $lang_id, "/main.ftl"))
}; };
} }
match lang { match lang {