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

feat: use profile for language #54

Merged
merged 9 commits into from
Aug 19, 2024
Merged

feat: use profile for language #54

merged 9 commits into from
Aug 19, 2024

Conversation

maelle
Copy link
Contributor

@maelle maelle commented Jul 17, 2024

@joelnitta would this solve #15?

A drawback is that one can not use babelquarto with more profiles (say, production vs development) but to me that seems fine.

@maelle
Copy link
Contributor Author

maelle commented Jul 17, 2024

@ntluong95 this would be relevant for you too. With that feature one could have a main configuration file and then a bunch of configuration files _quarto-en.yml, _quarto-fr.yml etc, each one featuring for instance the configuration of an announcement bar https://quarto.org/docs/websites/website-tools.html#announcement-bar

@Nenuial
Copy link
Collaborator

Nenuial commented Jul 19, 2024

That's a cool idea! I think it can help me solve some ideas I was having for bilingual navbars (elements that aren't linked to local pages).

Is this going to be merged or is this for discussion first?

@maelle
Copy link
Contributor Author

maelle commented Jul 19, 2024

@Nenuial thank you! I have opened it for discussion first and merging later. I'm about to be off for three weeks so won't merge it today. 😸

@Nenuial
Copy link
Collaborator

Nenuial commented Jul 19, 2024

Tanks for the answer. I'll install the PR and take it for a spin. I'll tell you how it goes in a week or two!

@maelle
Copy link
Contributor Author

maelle commented Jul 19, 2024

thank you!!

@Nenuial
Copy link
Collaborator

Nenuial commented Jul 31, 2024

I've played around with this PR and it's fantastic. It took some time to work out the best way to organise the configuration files. Each specific profile being merged with the main _quarto.yml, I had to wrap my head around "what is merged how".

But in the end I was able to make quite a satisfying website with a nicely translated navbar. For my part, I'm very much in favour of going this way with babelquarto!

@joelnitta
Copy link
Contributor

I haven't had a chance yet to test it out. @Nenuial are you able to share the source code and website? I'd love to see what you were able to do with it.

@Nenuial
Copy link
Collaborator

Nenuial commented Jul 31, 2024

No, sorry. I've experimented with a website that isn't going to be public and its repository isn't ready yet. But basically, what I did was to have 3 _quarto.yml files like so:

_quarto.yml (with all the other necessary configuration)

website:
  title: "MyTitle"
  navbar:
    logo: "resources/logo.png"
    background: "#2f466a"

_quarto-fr.yml

website:
  navbar:
    left:
      - text: "Accueil"
        href: index.qmd
      - text: "Discipline Fondamentale"
        menu: 
          - text: "Documents"
            href: https://url_to_other_website.xy
          - text: "Livre"
            href: https://url_to_other_website.xy/_book/fr

_quarto-en.yml

website:
  navbar:
    left:
      - text: "Home"
        href: index.qmd
      - text: "Foundational Discipline"
        menu: 
          - text: "Documents"
            href: https://url_to_other_website.xy
          - text: "Book"
            href: https://url_to_other_website.xy/_book

This was just a test, but it worked as expected.

@maelle
Copy link
Contributor Author

maelle commented Aug 12, 2024

@joelnitta do you think you'll be able to take this for a spin? No worries if not.

@ntluong95 see #54 (comment), I think this PR could be relevant to your needs too.

@Nenuial
Copy link
Collaborator

Nenuial commented Aug 18, 2024

A drawback is that one can not use babelquarto with more profiles (say, production vs development) but to me that seems fine.

Couldn't there be a profile argument to the render_website() and render_book() functions? The render part could then be:

quarto::quarto_render(
  as_job = FALSE,
  metadata = metadata,
  profile = c(main_language, profile)
)

And we would retain the ability to have more advanced use cases with multiple possible profiles.
I have tested it, and it works quite well.

@maelle
Copy link
Contributor Author

maelle commented Aug 19, 2024

Oh this is a neat idea! Let me give you write access if you want to push to this branch (but no pressure, I could also come to this later)

@maelle
Copy link
Contributor Author

maelle commented Aug 19, 2024

And the profile argument could default to whatever Quarto environment variable exists for profile 🤔

@Nenuial
Copy link
Collaborator

Nenuial commented Aug 19, 2024

Oh this is a neat idea! Let me give you write access if you want to push to this branch (but no pressure, I could also come to this later)

I added the changes to the profile branch in my fork. I tried pushing it to this profile branch but without success.

Edit: My bad!! I hadn't seen the invitation.

@maelle
Copy link
Contributor Author

maelle commented Aug 19, 2024

@Nenuial I added some docs (to that horribly long README 😅), what do you think?

@Nenuial
Copy link
Collaborator

Nenuial commented Aug 19, 2024

That's great! As mentioned in #46 I have started some work on reorganizing the documentation into smaller pieces but it's still a work in progress. I haven't started a part about customizing the template/navigation so it will fit perfectly in there.

@maelle
Copy link
Contributor Author

maelle commented Aug 19, 2024

Great! I'll go ahead and merge this. @joelnitta @ntluong95 feedback will be welcome after the merge too.

@maelle maelle merged commit 555d872 into main Aug 19, 2024
5 checks passed
@maelle maelle deleted the profile branch August 19, 2024 13:58
@joelnitta
Copy link
Contributor

joelnitta commented Sep 10, 2024

@maelle I finally got around to trying this on my webpage. Thanks for implementing it!

However I haven't gotten it to work quite as I'd like...

For example, in my navbar I have a button for my CV, which links directly to a PDF:

image

(source)

In the translated version of the webpage, this should read 履歴

But when I try to over-write it in _quarto-ja.yml, I end up with both buttons, not just the translated one:

image

You can see my attempt here: https://github.com/joelnitta/joelnitta-home/blob/profiles/_quarto-ja.yml

# Override language specific fields here
website:
  navbar:
    right:
      - href: content/pdf/Nitta_CV.pdf
        text: "履歴"

@Nenuial
Copy link
Collaborator

Nenuial commented Sep 10, 2024

Yes, that's because of the way Quarto merges the files when using profiles. Arrays don't overwrite, they merge and you get all elements. It's actually quite useful in some situations.

The solution is to have the English button in a _quarto-en.yml (and leave the Japanese one in _quarto-ja.yml). That way you shouldn't end up with the two buttons.

@maelle
Copy link
Contributor Author

maelle commented Sep 10, 2024

Thanks @joelnitta for testing and  @Nenuial for solving!

@joelnitta
Copy link
Contributor

joelnitta commented Sep 10, 2024

Thanks @Nenuial ! That seems to work.

However, I realized I now have a different problem: my translated blog posts aren't showing up properly...

My solution for that was to use a YAML like this for blog.ja.qmd:

---
title: "ブログ"
lang: ja
listing:
  contents: posts
  include:
    lang: ja
  sort: "date desc"
  type: default
  categories: true
comments: false
---

Where each of the blog posts with a Japanese translation have lang: ja in the YAML header (like this). When I render locally with the most recent babelquarto, I am not seeing the translated posts anymore. Could this be due to the new implementation?

Update: I can see now I need to tweak blog.ja.qmd, blog.en.qmd, and blog.qmd, but how these all come together in the end is still a bit shaky for me ...

@maelle
Copy link
Contributor Author

maelle commented Sep 10, 2024

Thanks @joelnitta, can you please open a new issue? I'm sorry that it's all so clunky. With your experience we might be able to improve the user experience or at least the docs. 😅

@Nenuial
Copy link
Collaborator

Nenuial commented Sep 11, 2024

That should work despite the changes made. I'll try to reproduce this in the next days and see if I can understand why this wouldn't work.

The use of filters for listings is now superfluous because the different language pages should no longer be present when rendering one specific language. But that shouldn't prevent this setup from working 🤔

@Nenuial
Copy link
Collaborator

Nenuial commented Sep 11, 2024

@joelnitta I tried reproducing the errors with the include key but was unable to do so. See my test repository here: https://github.com/Nenuial/babeltest

In both the french and english version of the posts.qmd page, the listing works even when I left the include: en and include: fr in place.

However, with the versions now cleaned up properly in subfolders, that include filter is no longer necessary and the listings also work nicely if you remove that part. Babelquarto should only see the files from that language.

@joelnitta
Copy link
Contributor

I realized that my problem is slightly different from what I originally described.

@Nenuial you are correct that the listing now works fine, and include is no longer necessary.

However, I am now encountering another problem. Please see this issue: #76

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

Successfully merging this pull request may close these issues.

3 participants