I am not entirely happy with the internal data structure, but that can be changed later. Now that messages are stored for multiple locales, work can start on generating code that can switch locales based on runtime input, rather than default to a single static locale as it currently does.
2XQ6ZB4WZNNR4KNC3VWNTV7IRMGGAEP33JPQUVB3CVWAKHECZVRQC
ROSR4HD5ENPQU3HH5IVYSOA5YM72W77CHVQARSD3T67BUNYG7KZQC
XGNME3WRU3MJDTFHUFJYARLVXWBZIH5ODBOIIFTXHNCBTZQH2R7QC
5FIVUZYFLOZ2CCH4GCOQQZFL3GDEB23VJ7J6YUXQDZQEAQDB76DQC
HJMYJDC77NLU44QZWIW7CELXJKD4EK4YZ6CCILYBG6FWGZ2KMBVAC
QSK7JRBA55ZRY322WXGNRROJL7NTFBR6MJPOOA5B2XD2JAVM4MWQC
VNSHGQYNPGKGGPYNVP4Z2RWD7JCSDJVYAADD6UXWBYL6ZRXKLE4AC
OCR4YRQ2LXK3PXSWPEWCBED4DFVMXZIF4RS35XQZSJ2D2KEIB2VQC
5TEX4MNUC4LDDRMNEOVCFNUUEZAGUXMKO3OIEQFXWRQKXSHY2NRQC
#[derive(Clone, Debug)]
struct LocalizationsForMessage {
canonical_message: Message<String>,
pub additional_messages: HashMap<Locale, Message<String>>,
}
impl LocalizationsForMessage {
fn new(canonical_message: Message<String>) -> Self {
Self {
canonical_message,
additional_messages: HashMap::new(),
}
}
}
pub fn from_resource(resource: Resource<String>, locale: Locale) -> Self {
let mut children = Vec::new();
pub fn new(canonical_locale: Locale, mut resources: HashMap<Locale, Resource<String>>) -> Self {
let canonical_resource = resources.remove(&canonical_locale).unwrap();
Self { locale, children }
for (locale, resource) in resources {
for entry in resource.body {
if let Entry::Message(message) = entry {
let localizations = messages.get_mut(&message.id.name).unwrap();
localizations
.additional_messages
.insert(locale.clone(), message);
}
}
}
Self {
canonical_locale,
messages,
}