-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server-side translation caching not yet supported. Translation engine still primitive. BREAKING CHANGE: all user-facing interfaces take new i18n parameters
- Loading branch information
1 parent
d1a6bb8
commit a4402c0
Showing
45 changed files
with
789 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,30 @@ | ||
use app::{get_config_manager, get_templates_vec}; | ||
use app::{get_config_manager, get_locales, get_templates_vec, get_translations_manager}; | ||
use futures::executor::block_on; | ||
use perseus::{build_templates, SsrNode}; | ||
use perseus::{build_app, SsrNode}; | ||
|
||
fn main() { | ||
let exit_code = real_main(); | ||
std::process::exit(exit_code) | ||
} | ||
|
||
fn real_main() -> i32 { | ||
let config_manager = get_config_manager(); | ||
let translations_manager = get_translations_manager(); | ||
let locales = get_locales(); | ||
|
||
let fut = build_templates(get_templates_vec::<SsrNode>(), &config_manager); | ||
// Build the site for all the common locales (done in parallel) | ||
let fut = build_app( | ||
get_templates_vec::<SsrNode>(), | ||
&locales, | ||
&config_manager, | ||
&translations_manager, | ||
); | ||
let res = block_on(fut); | ||
if let Err(err) = res { | ||
eprintln!("Static generation failed: '{}'", err); | ||
1 | ||
} else { | ||
println!("Static generation successfully completed!"); | ||
0 | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/target | ||
Cargo.lock | ||
|
||
.perseus/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "perseus-example-i18n" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
# Perseus itself, which we (amazingly) need for a Perseus app | ||
perseus = { path = "../../packages/perseus" } | ||
# Sycamore, the library Perseus depends on for lower-leve reactivity primitivity | ||
sycamore = { version = "0.5.1", features = ["ssr"] } | ||
sycamore-router = "0.5.1" | ||
# Serde, which lets you work with representations of data, like JSON | ||
serde = { version = "1", features = ["derive"] } | ||
serde_json = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Perseus Starter App</title> | ||
<!-- Importing this runs Perseus --> | ||
<script src="/.perseus/bundle.js" defer></script> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use perseus::ErrorPages; | ||
use sycamore::template; | ||
|
||
pub fn get_error_pages() -> ErrorPages { | ||
let mut error_pages = ErrorPages::new(Box::new(|_, _, _| { | ||
template! { | ||
p { "Another error occurred." } | ||
} | ||
})); | ||
error_pages.add_page( | ||
404, | ||
Box::new(|_, _, _| { | ||
template! { | ||
p { "Page not found." } | ||
} | ||
}), | ||
); | ||
error_pages.add_page( | ||
400, | ||
Box::new(|_, _, _| { | ||
template! { | ||
p { "Client error occurred..." } | ||
} | ||
}), | ||
); | ||
|
||
error_pages | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
mod error_pages; | ||
mod templates; | ||
|
||
use perseus::define_app; | ||
|
||
#[derive(perseus::Route)] | ||
pub enum Route { | ||
#[to("/<locale>")] | ||
Index { locale: String }, | ||
#[to("/<locale>/about")] | ||
About { locale: String }, | ||
#[not_found] | ||
NotFound, | ||
} | ||
|
||
define_app! { | ||
root: "#root", | ||
route: Route, | ||
router: { | ||
Route::Index { locale } => [ | ||
"index".to_string(), | ||
templates::index::template_fn(), | ||
locale | ||
], | ||
Route::About { locale } => [ | ||
"about".to_string(), | ||
templates::about::template_fn(), | ||
locale | ||
] | ||
}, | ||
error_pages: crate::error_pages::get_error_pages(), | ||
templates: [ | ||
crate::templates::index::get_template::<G>(), | ||
crate::templates::about::get_template::<G>() | ||
], | ||
locales: { | ||
default: "en-US", | ||
common: ["en-US", "fr-FR"], | ||
other: ["es-ES"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use perseus::{t, Template, Translator}; | ||
use std::rc::Rc; | ||
use std::sync::Arc; | ||
use sycamore::prelude::{component, template, GenericNode, Template as SycamoreTemplate}; | ||
|
||
#[component(AboutPage<G>)] | ||
pub fn about_page(translator: Rc<Translator>) -> SycamoreTemplate<G> { | ||
template! { | ||
// TODO switch to `t!` macro | ||
p { (translator.translate("about")) } | ||
} | ||
} | ||
|
||
pub fn template_fn<G: GenericNode>() -> perseus::template::TemplateFn<G> { | ||
Arc::new(|_, translator: Rc<Translator>| { | ||
template! { | ||
AboutPage(translator) | ||
} | ||
}) | ||
} | ||
|
||
pub fn get_template<G: GenericNode>() -> Template<G> { | ||
Template::new("about").template(template_fn()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use perseus::{t, Template, Translator}; | ||
use std::rc::Rc; | ||
use std::sync::Arc; | ||
use sycamore::prelude::{component, template, GenericNode, Template as SycamoreTemplate}; | ||
|
||
#[component(IndexPage<G>)] | ||
pub fn index_page(translator: Rc<Translator>) -> SycamoreTemplate<G> { | ||
template! { | ||
// TODO switch to `t!` macro | ||
p { (translator.translate("hello")) } | ||
a(href = "/en-US/about") { "About" } | ||
} | ||
} | ||
|
||
pub fn template_fn<G: GenericNode>() -> perseus::template::TemplateFn<G> { | ||
Arc::new(|_, translator: Rc<Translator>| { | ||
template! { | ||
IndexPage(translator) | ||
} | ||
}) | ||
} | ||
|
||
pub fn get_template<G: GenericNode>() -> Template<G> { | ||
Template::new("index").template(template_fn()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod about; | ||
pub mod index; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"hello": "Welcome to the app!", | ||
"about": "Welcome to the about page (English)!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"hello": "Hola!", | ||
"about": "Welcome to the about page (Spanish)!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"hello": "Bonjour!", | ||
"about": "Welcome to the about page (French)!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.