Skip to content
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

Multilingual bibliography #3177

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ecow = { version = "0.2", features = ["serde"] }
env_proxy = "0.4"
flate2 = "1"
fontdb = { version = "0.15", default-features = false }
hayagriva = "0.5.1"
hayagriva = {git = "https://github.com/nrydanov/hayagriva", branch = "feature/language-specific-terms"}
heck = "0.4"
hypher = "0.1.4"
iai = { git = "https://github.com/typst/iai", rev = "3f0f927" }
Expand Down
2 changes: 1 addition & 1 deletion crates/typst/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ comemo = { workspace = true }
csv = { workspace = true }
ecow = { workspace = true}
fontdb = { workspace = true }
hayagriva = { workspace = true }
hayagriva = { git = "https://github.com/nrydanov/hayagriva", branch = "feature/language-specific-terms" }
hypher = { workspace = true }
icu_properties = { workspace = true }
icu_provider = { workspace = true }
Expand Down
29 changes: 26 additions & 3 deletions crates/typst/src/model/bibliography.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::Arc;
use comemo::{Prehashed, Tracked};
use ecow::{eco_format, EcoString, EcoVec};
use hayagriva::archive::ArchivedStyle;
use hayagriva::citationberg::LocaleCode;
use hayagriva::io::BibLaTeXError;
use hayagriva::{
citationberg, BibliographyDriver, BibliographyRequest, CitationItem, CitationRequest,
Expand Down Expand Up @@ -711,9 +712,23 @@ impl<'a> Generator<'a> {
Some(CitationForm::Year) => Some(hayagriva::CitePurpose::Year),
};

let mut locale: Option<citationberg::LocaleCode> = None;
if let Some(lang) = entry.language() {
let lang_string = lang.language.as_str();
if let Some(value) = hayagriva::lang::codes::get_mapping(lang_string)
{
locale = Some(LocaleCode(String::from(value)));
}
}
normal &= special_form.is_none();
subinfos.push(CiteInfo { key, supplement, hidden });
items.push(CitationItem::new(entry, locator, None, hidden, special_form));
items.push(CitationItem::new(
entry,
locator,
locale,
hidden,
special_form,
));
}

if !errors.is_empty() {
Expand Down Expand Up @@ -749,10 +764,18 @@ impl<'a> Generator<'a> {
// bibliography.
if self.bibliography.full(StyleChain::default()) {
for entry in database.map.values() {
let mut locale: Option<citationberg::LocaleCode> = None;
if let Some(lang) = entry.language() {
let lang_string = lang.language.as_str();
if let Some(value) = hayagriva::lang::codes::get_mapping(lang_string)
{
locale = Some(LocaleCode(String::from(value)));
}
}
driver.citation(CitationRequest::new(
vec![CitationItem::new(entry, None, None, true, None)],
vec![CitationItem::new(entry, None, locale, true, None)],
bibliography_style.get(),
Some(locale.clone()),
None,
&LOCALES,
None,
));
Expand Down