From 096fefe7ed8bffe49837c4558925f408c1c6e2a8 Mon Sep 17 00:00:00 2001 From: Zdenek Crha <35028759+zdenek-crha@users.noreply.github.com> Date: Wed, 4 Sep 2019 20:30:32 +0200 Subject: [PATCH] Remove pub visibility from Config::translations hash (#796) The access to translations is not straightforward and requires checks if language and key exists. It is better to forbit direct access to attribute and provide method - `get_translation()` - that will handle all details of key translations. Remove unit tests that use direct access and test only public method. --- components/config/src/config.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/components/config/src/config.rs b/components/config/src/config.rs index 4f3dab51..7a387607 100644 --- a/components/config/src/config.rs +++ b/components/config/src/config.rs @@ -110,7 +110,10 @@ pub struct Config { /// /// The `String` key of `HashMap` is a language name, the value should be toml crate `Table` /// with String key representing term and value another `String` representing its translation. - pub translations: HashMap, + /// + /// The attribute is intentionally not public, use `get_translation()` method for translating + /// key into different language. + translations: HashMap, /// Whether to highlight all code blocks found in markdown files. Defaults to false pub highlight_code: bool, @@ -478,15 +481,6 @@ title = "Un titre" title = "A title" "#; - #[test] - fn can_use_language_configuration() { - let config = Config::parse(CONFIG_TRANSLATION); - assert!(config.is_ok()); - let translations = config.unwrap().translations; - assert_eq!(translations["fr"]["title"].as_str(), "Un titre"); - assert_eq!(translations["en"]["title"].as_str(), "A title"); - } - #[test] fn can_use_present_translation() { let config = Config::parse(CONFIG_TRANSLATION).unwrap();