-
Notifications
You must be signed in to change notification settings - Fork 1
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
twine extension #7
Open
rzerres
wants to merge
5
commits into
IMI-eRnD-Be:main
Choose a base branch
from
rzerres:wip_twine
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,8 @@ regex = "1" | |
[dev-dependencies] | ||
criterion = "0.3" | ||
tempfile = "3" | ||
|
||
[workspace] | ||
members = [ | ||
"twine-demo", | ||
] |
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,21 @@ | ||
[package] | ||
name = "twine-demo" | ||
version = "0.1.0" | ||
authors = ["Ralf Zerres <[email protected]>"] | ||
edition = "2018" | ||
build = "build.rs" | ||
|
||
[dependencies] | ||
serde = { version = "^1.0", features = ["derive"] } | ||
serde_json = { version = "^1.0" } | ||
substring = "1.4.5" | ||
tracing = "0.1.25" | ||
tracing-subscriber = "0.2.17" | ||
twine = { version = "^0.3", features = ["serde"] } | ||
|
||
[build-dependencies] | ||
twine = { version = "^0.3", features = ["serde"] } | ||
|
||
[[bin]] | ||
name = "twine-demo" | ||
path = "src/main.rs" |
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,6 @@ | ||
use twine::build_translations; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
build_translations(&["./src/i18n/localization.ini"], "i18n.rs").unwrap(); | ||
} |
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,59 @@ | ||
{ | ||
"_comment1": "The colour structure is an array of colour elements", | ||
"colour": [ | ||
{ | ||
"colour_name": "black", | ||
"category": "hue", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [255,255,255,1], | ||
"hex": "000" | ||
} | ||
}, | ||
{ | ||
"colour_name": "white", | ||
"category": "value", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [0,0,0,1], | ||
"hex": "FFF" | ||
} | ||
}, | ||
{ | ||
"colour_name": "red", | ||
"category": "hue", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [255,0,0,1], | ||
"hex": "FF0" | ||
} | ||
}, | ||
{ | ||
"colour_name": "blue", | ||
"category": "hue", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [0,0,255,1], | ||
"hex": "00F" | ||
} | ||
}, | ||
{ | ||
"colour_name": "yellow", | ||
"category": "hue", | ||
"colour_type": "Primary", | ||
"code": { | ||
"rgba": [255,255,0,1], | ||
"hex": "FF0" | ||
} | ||
}, | ||
{ | ||
"colour_name": "green", | ||
"category": "hue", | ||
"colour_type": "Secondary", | ||
"code": { | ||
"rgba": [0,255,0,1], | ||
"hex": "0F0" | ||
} | ||
} | ||
] | ||
} |
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,39 @@ | ||
[clock_drift] | ||
de = Uhrzeit ist eventuell rückwärts gestellt worden | ||
en = Clock may have gone backwards | ||
[err_lang_not_found] | ||
de = Konnte Sprachkode nicht auslesen | ||
en = Can not read the language code | ||
[err_import_colours] | ||
de = Import der Farbwert fehlgeschlagen | ||
en = Error importing coulour values | ||
[err_colour_not_found] | ||
de = Farbwert wurde nicht gefunden | ||
en = coulour value not found | ||
[lang_code] | ||
de = Sprachkode | ||
en = language code | ||
[main_started] | ||
de = Programmlogik starten | ||
en = Program logic started | ||
[main_finished] | ||
de = Programmlogik beendet | ||
en = Program logic finished | ||
[import_colours] | ||
de = Import der Farbwerte | ||
en = import coulour values | ||
[import_not_well_formed] | ||
de = JSON hat nicht die erwartete Struktur | ||
en = JSON was not well-formatted | ||
[import_started] | ||
de = Import aus einer Datei | ||
en = Import from a file | ||
[import_finished] | ||
de = Import aus einer Datei beendet | ||
en = Import from a file finished | ||
[state_started] | ||
de = gestartet | ||
en = started | ||
[state_finished] | ||
de = beended | ||
en = finished |
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,59 @@ | ||
#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)] | ||
|
||
use std::env; | ||
use std::time::SystemTime; | ||
use tracing::{trace, Level}; | ||
use tracing_subscriber::fmt; | ||
|
||
// get the macro (t!) accessing the internationalization strings | ||
include!(concat!(env!("OUT_DIR"), "/i18n.rs")); | ||
|
||
pub mod services; | ||
|
||
use crate::services::imports::*; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// initialize the tracing subsystem | ||
let span = tracing::span!(Level::TRACE, "wip_twine"); | ||
let _enter = span.enter(); | ||
let collector = fmt::Subscriber::builder() | ||
.with_max_level(tracing::Level::TRACE) | ||
.finish(); | ||
|
||
// start tracing thread | ||
tracing::subscriber::with_default(collector, || { | ||
// include localization strings | ||
let lang = Lang::De("de"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it weird that you are adding a Default impl but you don't seem to use it anywhere. May I ask, do you have an actual use case where you need |
||
let mut state = t!(state_started => lang); | ||
let mut res = t!(lang_code => lang); | ||
|
||
// localized feedback | ||
let time_start = SystemTime::now(); | ||
trace!(target: "twine-demo", state = ?state, | ||
res = ? res, time = ?time_start); | ||
|
||
match json_import::read_colours("data/demo.json") { | ||
Ok(colours) => { | ||
println!("We got {} colour elements", colours.colour.iter().count()); | ||
for (pos, e) in colours.colour.iter().enumerate() { | ||
println!("Element {}: colour name={:?}, rgba-value={:?}", pos, e.colour_name, e.code.rgba); | ||
} | ||
}, | ||
Err(e) => { | ||
println!("Error: {}!", e); | ||
res = t!(err_import_colours => lang); | ||
println!("Error: {}!", res); | ||
}, | ||
} | ||
|
||
state = t!(state_finished => lang); | ||
res = t!(import_colours => lang); | ||
|
||
// localized feedback | ||
let time_end = SystemTime::now(); | ||
let duration = time_end.duration_since(time_start); | ||
trace!(target: "twine-demo", process = ?res, state = ?state, duration = ?duration); | ||
}); | ||
|
||
Ok(()) | ||
} |
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,59 @@ | ||
use serde::Deserialize; | ||
use serde_json::Result; | ||
use std::{ | ||
fs::File, | ||
io::BufReader, | ||
path::Path, | ||
}; | ||
|
||
// Valid color types | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
pub enum Type { | ||
/// Primery colour | ||
Primary, | ||
/// Secondary colour | ||
Secondary, | ||
} | ||
|
||
impl Default for Type { | ||
fn default() -> Self { Type::Primary } | ||
} | ||
|
||
// Color codes structure | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
pub struct Code { | ||
/// Color code as an rgba array | ||
pub rgba: Vec<u8>, | ||
/// Color code as a hex value | ||
pub hex: String, | ||
} | ||
|
||
// The colour structure | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
pub struct Colour { | ||
pub colour_name: String, | ||
pub category: String, | ||
pub colour_type: Type, | ||
pub code: Code, | ||
} | ||
|
||
// The colours structure | ||
#[derive(Debug, Deserialize, PartialEq)] | ||
pub struct Colours { | ||
pub colour: Vec<Colour>, | ||
} | ||
|
||
pub fn read_colours<P>(path: P) -> Result<Colours> | ||
where | ||
P: AsRef<Path>, | ||
{ | ||
// Open the file in read-only mode with buffer | ||
let file = File::open(path).unwrap(); | ||
let reader = BufReader::new(file); | ||
|
||
// Read the JSON contents of the file as an instance of `Colours`. | ||
let colours: Colours = serde_json::from_reader(reader)?; | ||
|
||
// Return the `Colours` structure | ||
Ok(colours) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're still taking the first language in alphabetical order. This is not good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh,
didn't go into it. Actually i might just get rid of a default branch. User must choose explicitely for the language to choose.
I might implement something in the twine-demo code ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me