diff --git a/examples/multilingual.yml b/examples/multilingual.yml index 3dfaf51..2ab24db 100644 --- a/examples/multilingual.yml +++ b/examples/multilingual.yml @@ -1,2 +1,3 @@ languages: en-US: basic.yml +default_language: en-US diff --git a/packages/tribble-app/src/templates/workflow/get_build_paths.rs b/packages/tribble-app/src/templates/workflow/get_build_paths.rs index b6641c4..8c82531 100644 --- a/packages/tribble-app/src/templates/workflow/get_build_paths.rs +++ b/packages/tribble-app/src/templates/workflow/get_build_paths.rs @@ -14,7 +14,9 @@ pub async fn get_build_paths() -> RenderFnResult> { env::var("TRIBBLE_CONF").unwrap_or_else(|_| "../../../examples/basic.yml".to_string()); let root_cfg = Config::new(&root_cfg_file_path)?; match root_cfg { - Config::Root { languages } => { + Config::Root { languages, .. } => { + // We use a custom i18n system to avoid having to inject locales into the root `index.html` file (I spent two hours on that...) + // We just generate a page for each language/workflow combination // We assume workflows are the same for all languages, so we can choose a random one match languages.keys().collect::>().get(0) { Some(key) => { @@ -22,8 +24,15 @@ pub async fn get_build_paths() -> RenderFnResult> { let language_cfg = Config::new(language_cfg_path)?; match language_cfg { Config::Language { workflows, .. } => { + // Loop through those workflows and create a new page for each locale/workflow combination + let mut pages = Vec::new(); + for workflow_name in workflows.keys() { + for lang in languages.keys() { + pages.push(format!("{}/{}", lang, workflow_name)); + } + } // For each workflow, generate a separate page - Ok(workflows.keys().cloned().collect::>()) + Ok(pages) } // If a root file links to another root file, that's an invalid structure Config::Root { .. } => Err(ParserError::RootLinksToRoot { diff --git a/packages/tribble-app/src/templates/workflow/get_build_state.rs b/packages/tribble-app/src/templates/workflow/get_build_state.rs index 8d40dee..c289225 100644 --- a/packages/tribble-app/src/templates/workflow/get_build_state.rs +++ b/packages/tribble-app/src/templates/workflow/get_build_state.rs @@ -17,17 +17,26 @@ pub struct WorkflowProps { #[perseus::autoserde(build_state)] pub async fn get_build_state( path: String, - locale: String, + _locale: String, // We use our own purpose-built i18n system ) -> RenderFnResultWithCause { + // Strip off the `workflow/` section of the path (guaranteed to be there by Perseus) + let path = path.strip_prefix("workflow/").unwrap(); + let root_cfg_path = env::var("TRIBBLE_CONF").unwrap_or_else(|_| "../../../tribble.yml".to_string()); let root_cfg = Config::new(&root_cfg_path)?; let input_err_msg; + // This will be a different part of the path depending on whether or not we're using i18n + let workflow_name; // Get the workflows for the appropriate locale (if applicable) let workflows = match root_cfg { Config::Root { languages } => { + let path_vec: Vec<&str> = path.split('/').collect(); + // These two parts are guaranteed by the `get_build_paths` code + let locale = path_vec[0]; + workflow_name = path_vec[1]; // We want the language file for the current locale - let lang_cfg_path = match languages.get(&locale) { + let lang_cfg_path = match languages.get(locale) { Some(path) => path, // A language mismatch between Perseus and Tribble shouldn't be possible, because Tribble configures Perseus' locale settings None => unreachable!(), @@ -55,14 +64,13 @@ pub async fn get_build_state( workflows, input_err_msg: input_err_msg_l, } => { + workflow_name = path; input_err_msg = input_err_msg_l; workflows } }; - // Strip off the `workflow/` section of the path (Perseus guarantees that it will start with this) - let path = path.strip_prefix("workflow/").unwrap(); // Each workflow should match exactly to a page path (the pages are generated from the keys of the `workflows` map) - let workflow = match workflows.get(path) { + let workflow = match workflows.get(workflow_name) { Some(workflow) => workflow, None => unreachable!(), }; diff --git a/packages/tribble/src/main.rs b/packages/tribble/src/main.rs index 4231a0a..d8389fc 100644 --- a/packages/tribble/src/main.rs +++ b/packages/tribble/src/main.rs @@ -109,7 +109,12 @@ async fn core(dir: PathBuf) -> Result { .map_err(|err| ServeError::ParserError { source: err })?; if let Config::Root { languages } = cfg { for (_, lang_file_cfg_path) in languages { - dbg!(lang_file_cfg_path); + watcher + .watch(&lang_file_cfg_path, RecursiveMode::Recursive) + .map_err(|err| ServeError::WatchFileFailed { + filename: lang_file_cfg_path, + source: err, + })? } } @@ -125,6 +130,7 @@ async fn core(dir: PathBuf) -> Result { break Ok(build_exit_code); } } + // TODO Reload the browser automatically } Err(err) => break Err(ServeError::WatcherError { source: err }.into()), }