Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localization #159

Merged
merged 50 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7bfafff
Fresh start on the i18n translation.
BanjoFox Jun 21, 2018
031f145
Updating Comments
BanjoFox Jun 22, 2018
ce1f81e
Update comments
BanjoFox Jun 22, 2018
b029dfa
Update comments
BanjoFox Jun 22, 2018
7108105
Update pl.po
BanjoFox Jun 22, 2018
b2f87c8
Housekeeping
BanjoFox Jun 26, 2018
e8316d2
Merge branch 'i18n-templates' of github.com:Aardwolf-Social/aardwolf …
BanjoFox Jun 26, 2018
24e0b46
Adding Rust components to rocket_i18n
BanjoFox Jun 26, 2018
58ec4f9
Uh....
BanjoFox Jun 26, 2018
efea8a4
Merge remote-tracking branch 'origin/master' into i18n-templates
BanjoFox Jun 26, 2018
d33555d
Updating Cargo.toml
BanjoFox Jun 26, 2018
4fe7992
Fixing deps, trying to un-break things
BanjoFox Jun 26, 2018
d27c893
Updating rocket 0.4.0-dev
BanjoFox Jun 26, 2018
daeb35e
// Removed
BanjoFox Jun 26, 2018
f8f5a6e
Update Cargo.toml
BanjoFox Jun 26, 2018
b9b6e6d
Adding Crates.io rocket_i18n
BanjoFox Jun 26, 2018
b2c6d61
updates
BanjoFox Jun 26, 2018
36cd1aa
Getting closer
BanjoFox Jun 27, 2018
917bad9
One error left
BanjoFox Jun 27, 2018
f7e957e
Tweaking the package path
BanjoFox Jun 27, 2018
0d267a9
Merge branch 'rocket-master' into i18n-templates
BanjoFox Jun 28, 2018
033c402
Formatting
BanjoFox Jun 30, 2018
5de4d55
updates
BanjoFox Jun 30, 2018
613a06c
Adding macro feature
BanjoFox Jul 2, 2018
d6e6f74
Fairing updates
BanjoFox Jul 2, 2018
a9f3ff7
Re-adding rocket-i18n
BanjoFox Jul 2, 2018
4f666e3
Move rocket_i18n fairings
BanjoFox Jul 3, 2018
24a2580
Merge remote-tracking branch 'origin/documentation-rework' into i18n-…
BanjoFox Jul 6, 2018
c1a5fc3
Udating to match Babtiste's fixes
BanjoFox Jul 8, 2018
3df5098
Updating from diff
BanjoFox Jul 8, 2018
fc048f6
I18n templates (#144)
BanjoFox Jul 8, 2018
9cf76d3
Fixing sign_in/sign_up templates
BanjoFox Jul 8, 2018
35d83a3
Template re-work (part 2)
BanjoFox Jul 9, 2018
cb51eda
Merge remote-tracking branch 'origin/master' into i18n-templates
BanjoFox Oct 9, 2018
10d3d1e
Merge branch 'documentation-rework' into i18n-templates
BanjoFox Oct 9, 2018
2a7f6f2
Updating templates (serious this time)
BanjoFox Oct 13, 2018
7e38e2e
Merge remote-tracking branch 'origin/master' into i18n-templates
BanjoFox Oct 13, 2018
ba2630a
Updating example.toml
BanjoFox Oct 13, 2018
0f62381
Merge branch 'update-example-conf' into i18n-templates
BanjoFox Oct 13, 2018
e6df611
Updating Cargo versions.
BanjoFox Oct 13, 2018
4cf9469
Attempting to fix `#![feature(proc_macro_hygiene)]`
BanjoFox Oct 15, 2018
1112551
Merge remote-tracking branch 'origin/master' into i18n-templates
BanjoFox Oct 23, 2018
79b8264
More template work.
BanjoFox Oct 24, 2018
909f8c9
Reverting to nightly-2018-07-17
BanjoFox Oct 25, 2018
0c90649
Fix i18n-templates branch to compile (#153)
Oct 26, 2018
247e90e
Merge branch 'master' into asonix/i18n
asonix Nov 8, 2018
7f58584
Start manually fixing things
asonix Nov 8, 2018
49329c3
Bring in patched rocket_i18n
asonix Nov 8, 2018
ccb5f01
Get compile all the way TO aardwolf-rocket
asonix Nov 8, 2018
7619919
Everything compiles, rocket works. Actix is broken.
asonix Nov 9, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ diesel.toml
.config

node_modules

# Translations
.po~
translations
782 changes: 415 additions & 367 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ members = [
"aardwolf-models",
"aardwolf-types",
"aardwolf-rocket",
"aardwolf-actix"
"aardwolf-actix",
"rocket_i18n"
]

[features]
Expand Down
30 changes: 22 additions & 8 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ run. At the moment it has only been tested on linux, OSX, and Windows 10.

> NOTE: These instructions may help in installing a production version, but are
intended for developers to be able to build and test their changes. If in doubt,
seek out documentation from your distribution package or from [the `doc` folder](doc).
seek out documentation from your distribution package or from the [`doc`](doc) folder.

## Installing Requirements

Expand All @@ -15,20 +15,20 @@ In order to run the Aardwolf backend, you will need to have access to a
this guide we’re going to assume you are running the database on your
development machine.

Full Details can be found here:
[INSTALL-POSTGRES.md](/doc/INSTALL-POSTGRES.md)
[SETUP-POSTGRES.md](/doc/SETUP-POSTGRES.md)
Full details can be found here:

- [INSTALL-POSTGRES.md](/doc/INSTALL-POSTGRES.md)
- [SETUP-POSTGRES.md](/doc/SETUP-POSTGRES.md)

### Installing Rust Environment

Next, you’ll need to have the [Rust](https://rust-lang.org/) toolchain
installed. The best way to do this is to install
[rustup](https://rustup.rs), which is a Rust toolchain manager.

Full Details can be found here:
[INSTALL-RUST.md](/doc/INSTALL-RUST.md)
Full details can be found here:

- [INSTALL-RUST.md](/doc/INSTALL-RUST.md)

## Getting the source

Expand All @@ -47,14 +47,28 @@ We could continue to use the `+nightly` feature whenever we run a
override so cargo will know to use nightly by default whenever we’re in
our project directory. In the `aardwolf` directory, run

$ rustup override add nightly
$ rustup override set nightly

From now on, you won't have to use `+nightly` to run the correct
toolchain version.

__NOTE: For i18n-templates branch__

Currently to compile on the `i18n-templates` branch, the nightly version is pinned to `nightly-2018-07-17` (see [`rust_toolchain`](rust_toolchain)). To Install this specific version of nightly, run

$ rustup install nightly-2018-07-17

Then to set this nightly version on the project directory, in the `aardwolf` directory, run

$ rustup override set nightly-2018-07-17

To verify that the version in the project directory is what we just set, in the `aardwolf` directory, run

$ rustup show

## Configuring the server

Currently, Aardwolf expects aardwolf.toml to be in the root of the project
Currently, Aardwolf expects `aardwolf.toml` to be in the root of the project
directory. To get started, copy
[`config/example.toml`](config/example.toml) to
`./aardwolf.toml` and adjust the values accordingly.
Expand Down
6 changes: 5 additions & 1 deletion aardwolf-actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ collection_macros = "0.2.0"
config = "0.9.0"
failure = "0.1"
futures = "0.1"
handlebars = "1.1"
log = "0.4"
r2d2 = "0.8"
r2d2-diesel = "1.0"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
tera = "0.11"

[dependencies.aardwolf-models]
version = "0.1"
Expand All @@ -32,3 +32,7 @@ features = ["use-actix"]
version = "1.1"
default-features = false
features = ["postgres", "uuid", "chrono"]

[dependencies.rocket_i18n]
version = "0.1"
path = "../rocket_i18n"
37 changes: 28 additions & 9 deletions aardwolf-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ use actix_web::{
};
use config::Config;
use diesel::pg::PgConnection;
use handlebars::Handlebars;
use r2d2_diesel::ConnectionManager;
use rocket_i18n::I18n;
use tera::Tera;

#[macro_use]
pub mod action;
Expand All @@ -40,7 +41,8 @@ use self::db::{Db, Pool};
#[derive(Clone)]
pub struct AppConfig {
db: Addr<Db>,
templates: Arc<Handlebars>,
templates: Arc<Tera>,
i18n: Arc<I18n>,
}

impl fmt::Debug for AppConfig {
Expand All @@ -51,12 +53,28 @@ impl fmt::Debug for AppConfig {

impl AppConfig {
fn render<T: serde::Serialize>(&self, template: &str, data: &T) -> error::RenderResult {
self.templates
.render(template, data)
.map(|s| HttpResponse::Ok().header(CONTENT_TYPE, "text/html").body(s))
let attempts = vec![
template.to_owned(),
format!("{}.html", template),
format!("{}.html.tera", template),
];

let res = attempts
.iter()
.fold(None, |acc, template_name| {
acc.or_else(|| {
self.templates
.render(template_name, data)
.map_err(|e| error!("Error rendering, {}, {:?}", e, e))
.ok()
})
})
.ok_or(error::RenderError);

res.map(|s| HttpResponse::Ok().header(CONTENT_TYPE, "text/html").body(s))
.map_err(|e| {
error!("Unable to render template, {}", e);
error::RenderError
error!("Unable to render template");
e
})
}
}
Expand Down Expand Up @@ -117,8 +135,8 @@ pub fn run(config: Config, database_url: String) -> Result<(), Box<dyn Error>> {

let template_dir = config.get_str("Templates.dir")?;

let mut templates = Handlebars::new();
templates.register_templates_directory(".html.hbs", &template_dir)?;
let mut templates = Tera::new(&template_dir)?;
rocket_i18n::tera(&mut templates);

let templates = Arc::new(templates);

Expand All @@ -129,6 +147,7 @@ pub fn run(config: Config, database_url: String) -> Result<(), Box<dyn Error>> {
let state = AppConfig {
db: db.clone(),
templates: templates.clone(),
i18n: Arc::new(I18n::new("aardwolf")),
};

vec![
Expand Down
23 changes: 22 additions & 1 deletion aardwolf-actix/src/routes/personas.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use aardwolf_types::{
error::AardwolfFail,
forms::personas::{
CheckCreatePersonaPermission, CheckCreatePersonaPermissionFail,
CheckDeletePersonaPermission, CreatePersona, DeletePersona, FetchPersona,
PersonaCreationFail, PersonaCreationForm, PersonaDeletionFail, ValidatePersonaCreationForm,
},
Expand Down Expand Up @@ -42,6 +43,25 @@ impl From<PersonaCreationFail> for PersonaCreateError {
}
}

impl From<CheckCreatePersonaPermissionFail> for PersonaCreateError {
fn from(e: CheckCreatePersonaPermissionFail) -> Self {
match e {
CheckCreatePersonaPermissionFail::Database => PersonaCreateError::Database,
CheckCreatePersonaPermissionFail::Permission => PersonaCreateError::Permission,
}
}
}

impl From<DbActionError<CheckCreatePersonaPermissionFail>> for PersonaCreateError {
fn from(e: DbActionError<CheckCreatePersonaPermissionFail>) -> Self {
match e {
DbActionError::Connection => PersonaCreateError::Database,
DbActionError::Mailbox => PersonaCreateError::Mailbox,
DbActionError::Action(e) => e.into(),
}
}
}

impl From<DbActionError<PersonaCreationFail>> for PersonaCreateError {
fn from(e: DbActionError<PersonaCreationFail>) -> Self {
match e {
Expand All @@ -61,7 +81,8 @@ pub(crate) fn create(
PersonaCreateError,
[
(ValidateWrapper<_, _, _> => ValidatePersonaCreationForm),
(DbActionWrapper<_, _, _> => CreatePersona::new(user.0)),
(DbActionWrapper<_, _, _> => CheckCreatePersonaPermission::new(user.0)),
(DbActionWrapper<_, _, _> => CreatePersona),
]
);

Expand Down
5 changes: 4 additions & 1 deletion aardwolf-models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ failure = "0.1"
log = "0.4"
mime = "0.3"
rand = "0.5"
rocket = { version = "0.3.14", optional = true }
serde = "1.0"
serde_json = "1.0"
url = "1.7"
Expand All @@ -24,6 +23,10 @@ default = []
version = "1.2"
features = ["chrono", "postgres", "serde_json"]

[dependencies.rocket]
version = "0.4.0-rc.1"
optional = true

[dev-dependencies]
dotenv = "0.13"
env_logger = "0.5"
Expand Down
17 changes: 12 additions & 5 deletions aardwolf-rocket/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ config = "0.9.0"
failure = "0.1.1"
r2d2 = "0.8"
r2d2-diesel = "1.0"
rocket = "0.3.17"
rocket_codegen = "0.3.17"
serde = "1.0.21"
log = "0.4.1"

Expand All @@ -39,7 +37,16 @@ version = "1.1"
default-features = false
features = ["postgres", "uuid", "chrono"]

[dependencies.rocket]
version = "0.4.0-rc.1"

[dependencies.rocket_codegen]
version = "0.4.0-rc.1"

[dependencies.rocket_contrib]
version = "0.3.17"
default-features = false
features = ["handlebars_templates", "json"]
version = "0.4.0-rc.1"
features = ["tera_templates", "json"]

[dependencies.rocket_i18n]
version = "0.1"
path = "../rocket_i18n"
53 changes: 29 additions & 24 deletions aardwolf-rocket/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![recursion_limit = "128"]
#![feature(plugin)]
#![feature(custom_derive)]
#![plugin(rocket_codegen)]
#![feature(custom_derive, proc_macro_hygiene, decl_macro)]

extern crate aardwolf_models;
extern crate aardwolf_types;
Expand All @@ -16,8 +14,10 @@ extern crate diesel;
extern crate failure;
extern crate r2d2;
extern crate r2d2_diesel;
#[macro_use]
extern crate rocket;
extern crate rocket_contrib;
extern crate rocket_i18n;
extern crate serde;

use diesel::pg::PgConnection;
Expand All @@ -27,7 +27,6 @@ use rocket::{
request::{self, FromRequest},
Outcome, Request, Rocket, State,
};
use rocket_contrib::Template;
use std::{error::Error, ops::Deref};

#[macro_use]
Expand Down Expand Up @@ -73,46 +72,52 @@ fn app(config: config::Config, db_url: String) -> Result<Rocket, Box<dyn Error>>
.extra("database_url", db_url.as_str())
.unwrap();

let mut routes = routes![self::routes::app::home, self::routes::app::home_redirect,];
let mut routes = routes![routes::app::home, routes::app::home_redirect,];

#[cfg(debug_assertions)]
routes.extend(routes![
// webroot/favicon
self::routes::app::webroot,
routes::app::webroot,
// emoji
self::routes::app::emoji,
routes::app::emoji,
// themes
self::routes::app::themes,
routes::app::themes,
]);

let auth = routes![
self::routes::auth::sign_up_form,
self::routes::auth::sign_up_form_with_error,
self::routes::auth::sign_in_form,
self::routes::auth::sign_in_form_with_error,
self::routes::auth::sign_up,
self::routes::auth::sign_in,
self::routes::auth::confirm,
self::routes::auth::sign_out,
routes::auth::sign_up_form,
routes::auth::sign_up_form_with_error,
routes::auth::sign_in_form,
routes::auth::sign_in_form_with_error,
routes::auth::sign_up,
routes::auth::sign_in,
routes::auth::confirm,
routes::auth::sign_out,
];

let personas = routes![
self::routes::personas::new,
self::routes::personas::create,
self::routes::personas::delete,
self::routes::personas::switch,
routes::personas::new,
routes::personas::create,
routes::personas::delete,
routes::personas::switch,
];

let r = rocket::custom(c, true)
let r = rocket::custom(c)
.mount("/auth", auth)
.mount("/personas", personas)
.mount(
"/api/v1",
routes![self::routes::applications::register_application],
routes![routes::applications::register_application],
)
.mount("/", routes)
.attach(Template::fairing());
// .manage(SystemRandom::new());
// .manage(SystemRandom::new());
// Just for giggles, what happens if I put the rocket_i18n fairing here....
// Register the fairing. The parameter is the domain you want to use (the name of your app most of the time)
.attach(rocket_i18n::I18n::new("aardwolf"))
// Eventually register the Tera filters (only works with the master branch of Rocket)
.attach(rocket_contrib::templates::Template::custom(|engines| {
rocket_i18n::tera(&mut engines.tera);
}));

// we need an instance of the app to access the config values in Rocket.toml,
// so we pass it to the db_pool function, get the pool, and _then_ return the instance
Expand Down
Loading