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

Allow individual items to override locale when rendering references #268

Closed
elotroalex opened this issue Jul 20, 2019 · 21 comments
Closed

Comments

@elotroalex
Copy link
Collaborator

elotroalex commented Jul 20, 2019

I'm using chicago-fullnote-bibliography as my style. Given the following entry in the .bib file:

@article{pollock_ideologia_1987,
	title = {{Ideología y narrativa en el Ramayana de Valmiki}},
	number = {22},
	language = {es},
	journal = {Estudios de Asia y Africa},
	author = {Pollock, Sheldon I.},
	year = {1987},
	pages = {336--54}
}

I get this citation:

———. “Ideología y Narrativa En El Ramayana De Valmiki.” Estudios De Asia y Africa, no. 22 (1987): 336–54.

In Spanish the rule would lower case "Narrativa En El" and "De." The correct result should be:

———. “Ideología y narrativa en el Ramayana de Valmiki.” Estudios de Asia y Africa, no. 22 (1987): 336–54.

EDIT: Adding an edit here for context since the title of the issue changed. Originally I indicated that I was using use_raw_bibtex_entry: true and that it was not working as expected for the double braces.

@JoostvanPinxten
Copy link
Collaborator

JoostvanPinxten commented Jul 20, 2019

When use_raw_bibtex_entry:false, the liquid tags {{ }} in the bibtex input are evaluated.
On the contrary, setting it to false, just skips evaluating the input, and instead copies the bibtex entry 'raw'. You need to use this flag because you have double {{ braces in your bibtex:

{{Ideología y narrativa en el Ramayana de Valmiki}}

The capitalization of the words, however, is done according to the CSL file. However, I think the capitalization is overridden somewhat due to the protected bibtex field (i.e. the double braces). Normally, this would mean that the capitalization is kept the same as in the input.

In your case, I don't know exactly how it should be rendered, but the use_raw_bibtex is unlikely to be the problem here.

Try removing one of the pair of braces around the title, it might fix the issue. Otherwise, the issue might be in an updated CSL style for the chosen citation style.

@inukshuk
Copy link
Owner

Yes, this happens because the style uses title-case.

Looking at the CSL spec I just noticed that title-case conversion should be skipped for non-English references. That's something we missed in citeproc-ruby but it should be easy to fix there. I'll try to do that.

If you use only non English references or if you know that the casing in your BibTeX file is already correct, you could also remove title-casing from the style as a temporary workaround (on a quick glance, I believe the appropriate place might be here).

@inukshuk
Copy link
Owner

Hmm, turns out this is already implemented in citeproc-ruby after all, so you're probably right that this used to work already and we broke it somewhere.

@inukshuk
Copy link
Owner

Sorry for the noise but I think this is actually not implemented in jekyll-scholar. If all your references are Spanish, you could set locale to es in your jekyll-scholar configuration and that should turn off title-casing for all references.

Switching locale per item is currently not implemented in jekyll-scholar, but it should be easy to do if there is demand for it.

@elotroalex
Copy link
Collaborator Author

elotroalex commented Jul 20, 2019 via email

@elotroalex
Copy link
Collaborator Author

elotroalex commented Jul 20, 2019 via email

@inukshuk
Copy link
Owner

citeproc-ruby actually has a feature that will let each item override the locale using its 'language' field. This would affect not only title-casing but everything that can be localized in CSL (e.g., dates, ordinals, certain terms like 'ibid', and so on).

To get the same in scholar, we would just have to do something like this in jekyll-scholar around here: basically, set renderer.locale to the item's locale before renderer.render is invoked and re-setting the original locale in an ensure block.

Ideally we'd also cache locales (similar to styles) so that we don't keep parsing the same locale files over and over again.

@inukshuk inukshuk changed the title use_raw_bibtex_entry: true does not seem to be working Allow individual items to override locale when rendering references Jul 20, 2019
@elotroalex
Copy link
Collaborator Author

I can give it a spin in the afternoon and send a PR. I'll let you know if I get stumped.

@elotroalex
Copy link
Collaborator Author

Ok. Gave it a shot for the past couple of hours. I built the gem locally and went to town tweaking. Now officially stumped. Everything is finally running without exceptions. Except, the citation is still rendering with the capital letters. Any ideas?

      def render_bibliography(entry, index = nil)

      entry.language = entry['language']  

      unless entry.language == ""
        if config['allow_locale_overrides'] == true && entry.language != config['locale']
          begin
            new_locale = CSL::Locale.load(entry.language) 
            unless new_locale.nil?
              original_locale, @locale = @locale, new_locale
            end
          rescue ParseError
            # locale not found
          end
        end

        renderer.render citation_item_for(entry, index),
            styles(style).bibliography
      end

      ensure
        unless original_locale.nil?
          @locale = original_locale
        end
    end

@elotroalex
Copy link
Collaborator Author

elotroalex commented Jul 20, 2019

Also:

allow_locale_overrides is now a thing on config and it's set to true in my rig. The only predictable but minor annoyance if we get this to work is that we would have to make sure that the the .bib file is using the two letter standard for localization, i.e. 'en','es', etc.

@elotroalex
Copy link
Collaborator Author

Did we give up on getting the CSL to respect double braces? I couldn't understand if it was just impossible. The pipeline remains somewhat mysterious to me.

@elotroalex
Copy link
Collaborator Author

elotroalex commented Jul 20, 2019

Fixed it! Doh. I was changing the @locale instead of renderer.locale. And it worked:

———. «Ideología y narrativa en el Ramayana de Valmiki». Estudios de Asia y Africa, n.º 22 (1987): 336-54.

Well, "worked," since it rendered the wrong type of quotes. Now gotta go see if I can get it to return to the original locale. ...

@inukshuk
Copy link
Owner

Yes, those are the quotes defined by the Spanish locale: like I mentioned, this change renders the whole citation using Spanish locale (notice also the different ordinals). If only the quotes are an issue, you could adjust the Spanish locale to use different quotes... but if you want to render the reference using English locale but skip title-casing I think we'll need to work around this differently.

@elotroalex
Copy link
Collaborator Author

Ok. First part in PR already. I'm not sure I feel comfortable doing the cache part. I went and looked and it looked a bit over my pay grade.

@elotroalex
Copy link
Collaborator Author

Yes, those are the quotes defined by the Spanish locale: like I mentioned, this change renders the whole citation using Spanish locale (notice also the different ordinals). If only the quotes are an issue, you could adjust the Spanish locale to use different quotes... but if you want to render the reference using English locale but skip title-casing I think we'll need to work around this differently.

I read up on the manual, and other styles, and it is perfectly legitimate to have different quote systems according to the languages if you're mixing it up. I say we should go with this solution.

inukshuk added a commit that referenced this issue Jul 21, 2019
@inukshuk
Copy link
Owner

Looks great! I added the locale cache and a test for this.

@inukshuk
Copy link
Owner

If you could document the allow_locale_overrides option that would be great (maybe also locale unless that's documented already). I'll push 5.15.0 to RubyGems later today.

@inukshuk
Copy link
Owner

You have also earned write access to the repo is you want it!

https://github.com/inukshuk/jekyll-scholar/invitations

@elotroalex
Copy link
Collaborator Author

Thanks! I'll push the documentation in the next couple of hours.

@elotroalex
Copy link
Collaborator Author

Done. Glad we got this working. Enjoyed studying your refactoring, and the test you wrote. Little by little I'm getting a sense of how it all ties together.

@inukshuk
Copy link
Owner

Awesome, thanks for getting this done!

Just pushed 5.15.0 to RubyGems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants