From e5f4bb656b23c046c2280336f531c9e9d3d03ad1 Mon Sep 17 00:00:00 2001 From: cshjsc Date: Tue, 21 Mar 2023 18:25:39 +0100 Subject: [PATCH] Fix extra quotes for languages, sort the languages by name and move the lang json file to data dir --- languages.json => data/languages.json | 0 src/lib.rs | 12 ++++++++---- src/wiki/language.rs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) rename languages.json => data/languages.json (100%) diff --git a/languages.json b/data/languages.json similarity index 100% rename from languages.json rename to data/languages.json diff --git a/src/lib.rs b/src/lib.rs index d2f6a039..6b9e7ceb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,8 @@ -use std::{collections::HashMap, fs::File, io::BufReader}; +use std::{ + collections::{BTreeMap, HashMap}, + fs::File, + io::BufReader, +}; use proc_macro::TokenStream; use serde::{de::IgnoredAny, Deserialize, Serialize}; @@ -45,7 +49,7 @@ pub fn parse_languages(input: TokenStream) -> TokenStream { .site_matrix .languages .into_iter() - .fold(HashMap::new(), |mut acc, e| { + .fold(BTreeMap::new(), |mut acc, e| { let mut e = e.1; let name = if acc.contains_key(&e.localname) { normalize_string(&(e.localname.clone() + &e.code)) @@ -71,11 +75,11 @@ pub fn parse_languages(input: TokenStream) -> TokenStream { }; language_data_arms = quote! { #language_data_arms - Language::#ident => (stringify!(#en_name), stringify!(#lang_name), stringify!(#lang_code)), + Language::#ident => (#en_name, #lang_name, #lang_code), }; from_str_arms = quote! { #from_str_arms - stringify!(#lang_code) | stringify!(#lang_name) => Language::#ident, + #lang_code | #lang_name => Language::#ident, }; array_def = quote! { #array_def diff --git a/src/wiki/language.rs b/src/wiki/language.rs index b90960aa..52c3c7b6 100644 --- a/src/wiki/language.rs +++ b/src/wiki/language.rs @@ -2,4 +2,4 @@ use serde::Serialize; use wiki_tui::parse_languages; // This macro parses all the available wikipedia languages into an enum -parse_languages!("./languages.json"); +parse_languages!("./data/languages.json");