Skip to content

Commit

Permalink
Fix extra quotes for languages, sort the languages by name and move t…
Browse files Browse the repository at this point in the history
…he lang json file to data dir
  • Loading branch information
cshjsc committed Mar 21, 2023
1 parent 43efcfe commit e5f4bb6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
File renamed without changes.
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/wiki/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

0 comments on commit e5f4bb6

Please sign in to comment.