mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
convert the other languages into folders
This commit is contained in:
parent
3295ff2c58
commit
00140384f7
17
assets/voxygen/i18n/README.md
Normal file
17
assets/voxygen/i18n/README.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Translation document instructions
|
||||
|
||||
In order to keep localization documents readible please follow the following
|
||||
rules:
|
||||
- separate the string map sections using a commentary describing the purpose
|
||||
of the next section
|
||||
- prepend multi-line strings with a commentary
|
||||
- append one blank lines after a multi-line strings and two after sections
|
||||
|
||||
|
||||
# Adding a new language in Veloren
|
||||
|
||||
To add a new language in Veloren, please follow these steps:
|
||||
- Create a new folder into the `assets/voxygen/i18n` directory
|
||||
- Copy the content of the `en` directory
|
||||
- Configure the language metadata in the `_root.ron` file
|
||||
- From this point, you can start translating the files !
|
@ -1,15 +1,3 @@
|
||||
/// Translation document instructions
|
||||
///
|
||||
/// In order to keep localization documents readible please follow the following
|
||||
/// rules:
|
||||
/// - separate the string map sections using a commentary describing the purpose
|
||||
/// of the next section
|
||||
/// - prepend multi-line strings with a commentary
|
||||
/// - append one blank lines after a multi-line strings and two after sections
|
||||
///
|
||||
/// To add a new language in Veloren, just write an additional `.ron` file in
|
||||
/// `assets/voxygen/i18n` and that's it!
|
||||
///
|
||||
/// WARNING: Localization files shall be saved in UTF-8 format without BOM
|
||||
|
||||
/// Localization for "global" English
|
@ -188,20 +188,23 @@ impl assets::Loader<Localization> for LocalizationLoader {
|
||||
}
|
||||
impl assets::Loader<LocalizationFragment> for LocalizationLoader {
|
||||
fn load(content: Cow<[u8]>, ext: &str) -> Result<LocalizationFragment, assets::BoxedError> {
|
||||
let mut asked_localization: LocalizationFragment = assets::RonLoader::load(content, ext)?;
|
||||
Ok(asked_localization)
|
||||
let asked_fragment: LocalizationFragment = assets::RonLoader::load(content, ext)?;
|
||||
Ok(asked_fragment)
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes and return a Localization with the given key
|
||||
pub fn init_localization(asset_key: &str) -> Result<Localization, assets::BoxedError> {
|
||||
// retrieve a Localization struct, clone it to allow writing
|
||||
let mut asked_localization = Localization::load(&(asset_key.to_string() + "._self"))?.cloned();
|
||||
// handle localization files
|
||||
// for this, we load a special file called "_root.ron"
|
||||
let mut asked_localization = Localization::load(&(asset_key.to_string() + "._root"))?.cloned();
|
||||
|
||||
// walk through files in the folder, collecting localization fragment to merge inside the asked_localization
|
||||
for localization_asset in assets::load_dir::<LocalizationFragment>(asset_key)?.iter() {
|
||||
asked_localization.string_map.extend(localization_asset.read().string_map.clone());
|
||||
asked_localization.vector_map.extend(localization_asset.read().vector_map.clone());
|
||||
}
|
||||
// handle localization sub directories
|
||||
// use the localization's subdirectory list to load fragments from there
|
||||
for sub_directory in asked_localization.sub_directories.iter() {
|
||||
for localization_asset in assets::load_dir::<LocalizationFragment>(&(asset_key.to_string() + "." + &sub_directory))?.iter() {
|
||||
asked_localization.string_map.extend(localization_asset.read().string_map.clone());
|
||||
@ -225,6 +228,8 @@ pub fn init_localization(asset_key: &str) -> Result<Localization, assets::BoxedE
|
||||
Ok(asked_localization)
|
||||
}
|
||||
|
||||
/// Initializes and return a Localization with the given key
|
||||
/// Panics if the Localization cannot be found
|
||||
#[track_caller]
|
||||
pub fn init_localization_expect(asset_key: &str) -> Localization {
|
||||
init_localization(asset_key).unwrap_or_else(|err| {
|
||||
|
Loading…
Reference in New Issue
Block a user