ropensci-review-tools / babelquarto

Renders a Multilingual Quarto Project (Book or Website)
https://docs.ropensci.org/babelquarto/
Other
39 stars 7 forks source link

'Home' button doesn't get translated in websites #15

Closed joelnitta closed 3 weeks ago

joelnitta commented 1 year ago

This is only relevant for #11.

The 'home' button appears the same in the translated website, but I would like to have it translated into the target language:

image

joelnitta commented 1 year ago

Nevermind, figured it out:

The text field should not be used under website in _quarto.yml.

For example,

website:
  title: "Joel Nitta"
  navbar:
    right:
      - href: index.qmd
      - href: publications.qmd

Then, set title to the title in the preferred language in each of index.qmd and (for example), index.ja.qmd.

For example,

---
title: ホーム
lang: ja
...
joelnitta commented 1 year ago

...Sorry for the confusion. Turns out I'm still having problems. I am unable to set title to "Home" for ./index.qmd because I am using an About page for ./index.qmd, and title needs to be my name so it shows up below my profile picture.

image

Work around for now is just not to have an "About" button in the navbar, which is not so terrible... so this is not high priority.

maelle commented 1 year ago

I wonder now why have home in the navbar though? I know that's what I did in the example, but since there's the link at the top left, isn't it too much?

joelnitta commented 1 year ago

Yes. As I mentioned above, I also realized it's OK just not to have the additional "About" in the navbar. Please feel free to close if you want.

... But I would just say there are some cases where you might want to have slightly different text in the navbar that the page title. The text field under website in _quarto.yml would normally allow you to do so, but since there is only one _quarto.yml for both languages, we can't have a text in it for each language.

maelle commented 1 year ago

Ok, let's leave it open.

We have title-ja etc, I'll have to think about how to store other translations. I'd like to not have more than the Quarto configuration and the translated files but maybe I'll end up having to adopt po files or something :scream_cat:

maelle commented 1 year ago

for book parts babelquarto detects fields such as "part-es", maybe it could be the same, would that be cumbersome :thinking:

maelle commented 1 year ago

maybe there should be a general solution: for any field in _quarto.yml, if there's a "sibling" field called the same name + an hyphen + a language code, use it instead when rendering the language in question.

Could that backfire somehow (could another field be called "the same name + an hyphen + a language code" without being a translation :sweat_smile:)

joelnitta commented 1 year ago

I think that sounds good. That would enable having a single _quarto.yml with different options for different languages.

I don't think the backfire situation is likely. But there should be a list of all quarto fields somewhere that you could check.

maelle commented 1 year ago

@joelnitta

brio::read_lines("joel.yaml")
#>  [1] "project:"                                  
#>  [2] "  type: website"                           
#>  [3] ""                                          
#>  [4] "website:"                                  
#>  [5] "  title: \"Joel Nitta\""                   
#>  [6] "  navbar:"                                 
#>  [7] "    background: primary"                   
#>  [8] "    right:"                                
#>  [9] "      - href: index.qmd"                   
#> [10] "        text: Home"                        
#> [11] "      - href: publications.qmd"            
#> [12] "        text: Publications"                
#> [13] "      - href: software.qmd"                
#> [14] "        text: Software"                    
#> [15] "      - href: blog.qmd"                    
#> [16] "        text: Blog"                        
#> [17] "      - href: talks.qmd"                   
#> [18] "        text: Talks"                       
#> [19] "      - href: content/pdf/Nitta_CV.pdf"    
#> [20] "        text: \"CV\""                      
#> [21] "      - href: https://www.ja.joelnitta.com"
#> [22] "        text: \"Japanese\""                
#> [23] ""                                          
#> [24] "format:"                                   
#> [25] "  html:"                                   
#> [26] "    theme:"                                
#> [27] "      light: cosmo"                        
#> [28] "      dark: superhero"                     
#> [29] "    css: jnitta_theme.css"                 
#> [30] "    toc: true"                             
#> [31] "    comments:"                             
#> [32] "      giscus:"                             
#> [33] "        repo: joelnitta/joelnitta-home"    
#> [34] "        repo-id: R_kgDOGZGr3w"             
#> [35] "        category: Comments"                
#> [36] "        category-id: DIC_kwDOGZGr384B_-52" 
#> [37] "        mapping: pathname"                 
#> [38] "        reactions-enabled: false"          
#> [39] "        input-position: top"               
#> [40] "        theme: light"                      
#> [41] "        language: en"                      
#> [42] "    include-in-header: header.html"        
#> [43] ""                                          
#> [44] "babelquarto-ja:"                           
#> [45] "  format:"                                 
#> [46] "    html:"                                 
#> [47] "      comments:"                           
#> [48] "        giscus:"                           
#> [49] "          language: ja"
yaml <- yaml::read_yaml("joel.yaml")

(general_fields <- yaml[!grepl("^babelquarto-", names(yaml))])
#> $project
#> $project$type
#> [1] "website"
#> 
#> 
#> $website
#> $website$title
#> [1] "Joel Nitta"
#> 
#> $website$navbar
#> $website$navbar$background
#> [1] "primary"
#> 
#> $website$navbar$right
#> $website$navbar$right[[1]]
#> $website$navbar$right[[1]]$href
#> [1] "index.qmd"
#> 
#> $website$navbar$right[[1]]$text
#> [1] "Home"
#> 
#> 
#> $website$navbar$right[[2]]
#> $website$navbar$right[[2]]$href
#> [1] "publications.qmd"
#> 
#> $website$navbar$right[[2]]$text
#> [1] "Publications"
#> 
#> 
#> $website$navbar$right[[3]]
#> $website$navbar$right[[3]]$href
#> [1] "software.qmd"
#> 
#> $website$navbar$right[[3]]$text
#> [1] "Software"
#> 
#> 
#> $website$navbar$right[[4]]
#> $website$navbar$right[[4]]$href
#> [1] "blog.qmd"
#> 
#> $website$navbar$right[[4]]$text
#> [1] "Blog"
#> 
#> 
#> $website$navbar$right[[5]]
#> $website$navbar$right[[5]]$href
#> [1] "talks.qmd"
#> 
#> $website$navbar$right[[5]]$text
#> [1] "Talks"
#> 
#> 
#> $website$navbar$right[[6]]
#> $website$navbar$right[[6]]$href
#> [1] "content/pdf/Nitta_CV.pdf"
#> 
#> $website$navbar$right[[6]]$text
#> [1] "CV"
#> 
#> 
#> $website$navbar$right[[7]]
#> $website$navbar$right[[7]]$href
#> [1] "https://www.ja.joelnitta.com"
#> 
#> $website$navbar$right[[7]]$text
#> [1] "Japanese"
#> 
#> 
#> 
#> 
#> 
#> $format
#> $format$html
#> $format$html$theme
#> $format$html$theme$light
#> [1] "cosmo"
#> 
#> $format$html$theme$dark
#> [1] "superhero"
#> 
#> 
#> $format$html$css
#> [1] "jnitta_theme.css"
#> 
#> $format$html$toc
#> [1] TRUE
#> 
#> $format$html$comments
#> $format$html$comments$giscus
#> $format$html$comments$giscus$repo
#> [1] "joelnitta/joelnitta-home"
#> 
#> $format$html$comments$giscus$`repo-id`
#> [1] "R_kgDOGZGr3w"
#> 
#> $format$html$comments$giscus$category
#> [1] "Comments"
#> 
#> $format$html$comments$giscus$`category-id`
#> [1] "DIC_kwDOGZGr384B_-52"
#> 
#> $format$html$comments$giscus$mapping
#> [1] "pathname"
#> 
#> $format$html$comments$giscus$`reactions-enabled`
#> [1] FALSE
#> 
#> $format$html$comments$giscus$`input-position`
#> [1] "top"
#> 
#> $format$html$comments$giscus$theme
#> [1] "light"
#> 
#> $format$html$comments$giscus$language
#> [1] "en"
#> 
#> 
#> 
#> $format$html$`include-in-header`
#> [1] "header.html"

(japenese_fields <- modifyList(general_fields, yaml[["babelquarto-ja"]]))
#> $project
#> $project$type
#> [1] "website"
#> 
#> 
#> $website
#> $website$title
#> [1] "Joel Nitta"
#> 
#> $website$navbar
#> $website$navbar$background
#> [1] "primary"
#> 
#> $website$navbar$right
#> $website$navbar$right[[1]]
#> $website$navbar$right[[1]]$href
#> [1] "index.qmd"
#> 
#> $website$navbar$right[[1]]$text
#> [1] "Home"
#> 
#> 
#> $website$navbar$right[[2]]
#> $website$navbar$right[[2]]$href
#> [1] "publications.qmd"
#> 
#> $website$navbar$right[[2]]$text
#> [1] "Publications"
#> 
#> 
#> $website$navbar$right[[3]]
#> $website$navbar$right[[3]]$href
#> [1] "software.qmd"
#> 
#> $website$navbar$right[[3]]$text
#> [1] "Software"
#> 
#> 
#> $website$navbar$right[[4]]
#> $website$navbar$right[[4]]$href
#> [1] "blog.qmd"
#> 
#> $website$navbar$right[[4]]$text
#> [1] "Blog"
#> 
#> 
#> $website$navbar$right[[5]]
#> $website$navbar$right[[5]]$href
#> [1] "talks.qmd"
#> 
#> $website$navbar$right[[5]]$text
#> [1] "Talks"
#> 
#> 
#> $website$navbar$right[[6]]
#> $website$navbar$right[[6]]$href
#> [1] "content/pdf/Nitta_CV.pdf"
#> 
#> $website$navbar$right[[6]]$text
#> [1] "CV"
#> 
#> 
#> $website$navbar$right[[7]]
#> $website$navbar$right[[7]]$href
#> [1] "https://www.ja.joelnitta.com"
#> 
#> $website$navbar$right[[7]]$text
#> [1] "Japanese"
#> 
#> 
#> 
#> 
#> 
#> $format
#> $format$html
#> $format$html$theme
#> $format$html$theme$light
#> [1] "cosmo"
#> 
#> $format$html$theme$dark
#> [1] "superhero"
#> 
#> 
#> $format$html$css
#> [1] "jnitta_theme.css"
#> 
#> $format$html$toc
#> [1] TRUE
#> 
#> $format$html$comments
#> $format$html$comments$giscus
#> $format$html$comments$giscus$repo
#> [1] "joelnitta/joelnitta-home"
#> 
#> $format$html$comments$giscus$`repo-id`
#> [1] "R_kgDOGZGr3w"
#> 
#> $format$html$comments$giscus$category
#> [1] "Comments"
#> 
#> $format$html$comments$giscus$`category-id`
#> [1] "DIC_kwDOGZGr384B_-52"
#> 
#> $format$html$comments$giscus$mapping
#> [1] "pathname"
#> 
#> $format$html$comments$giscus$`reactions-enabled`
#> [1] FALSE
#> 
#> $format$html$comments$giscus$`input-position`
#> [1] "top"
#> 
#> $format$html$comments$giscus$theme
#> [1] "light"
#> 
#> $format$html$comments$giscus$language
#> [1] "ja"
#> 
#> 
#> 
#> $format$html$`include-in-header`
#> [1] "header.html"

Created on 2023-09-29 with reprex v2.0.2

maelle commented 8 months ago

I'm sorry to drop the ball on this, but I won't have time to work on this in the sort/medium term. :disappointed: If you have time to, I'd be glad to give you write access and add you as an author.

@beamilz you too might be interested in more configuration tweaks between languages. After using language profiles for something else recently, I agree it'd be a good idea! Then each rendering would "just" need to set the correct environment variable.

joelnitta commented 3 weeks ago

Related comment: https://github.com/ropensci-review-tools/babelquarto/pull/54#issuecomment-2339444329

maelle commented 3 weeks ago

If @Nenuial's suggestion works, it means we solved this issue, correct?

joelnitta commented 3 weeks ago

I don't think so, for the reason that we still don't have complete control over translation of the content in the navbar.

For a minimal example, please see this repo: https://github.com/joelnitta/test-babelq-profiles

In my translation, I want to have different text on the navbar for each of index.qmd and about.qmd, and only those two. I cannot, because _quarto.yml is required to include at least the following:

website:
  title: "test-site"
  navbar:
    left:
      - index.qmd

It is not possible to have

website:
  title: "test-site"

or

website:
  title: "test-site"
  navbar: left

So the translated text for index.qmd and about.qmd shows up in addition to the default text for index.qmd (in this example, test-site-name in English and サイトの名前 in Japanese).

image

image

Nenuial commented 3 weeks ago

I'm not sure I understand what you are trying to do.

You want index.qmd and about.qmd to show up in the navbar? In each language with their respective title? I don't understand why that shouldn't be possible.

Or you want those two pages to show up in the navbar with a text that is different from their title?

joelnitta commented 3 weeks ago

This has expanded a bit past the OP, but I would like to be able to control each item in the navbar.

My answer is "yes" to both of your questions. I would like to be able to control the name of the page in the navbar separately from its title on the page.

I would like to be able to avoid having to include at least one item under website: navbar: left: in _quarto.yml because it forces that item to appear in the navbar, and I cannot control its appearance from the language-specific profiles.

Nenuial commented 3 weeks ago

I don't understand why you can't control everything from the profiles _quarto-en.yml and _quarto-ja.yml.

For a different title you could do something along the lines of:

website:
  navbar:
    left:
      - text: "The title you want"
        href: index.qmd
      - about.qmd

In _quarto-en.yml. This changes the title shown for index.qmd but reads the title from the about.qmd file.

Depending on what you want, that means you will have to repeat some of the navbar configuration in both _quarto-en.yml and _quarto-ja.yml but it gives you full control over the navbar in both languages and you can fine tune it to the exact look of the navbar in each language.

joelnitta commented 3 weeks ago

Did you see my code? The problem is that setting text for href: index.qmd in _quarto-en.yml does not overwrite the one from _quarto.yml but instead adds to it (as you explained to me earlier).

_quarto-en.yml

website:
  navbar:
    left:
      - href: index.qmd
        text: Home
      - href: about.qmd
        text: About
Nenuial commented 3 weeks ago

Oh! I think I understand what you mean! You need to have a navbar configuration present in the _quarto.yml file, otherwise babelquarto fails some checks?

I have the following on one of my website in the _quarto.yml:

website:
  navbar:
    background: "#ffffff"

This way there's a navbar key present but no content. All the navbar content is defined in the language profiles, nothing is set in the main _quarto.yml file.

joelnitta commented 3 weeks ago

Yes, that is what I'm going for. Except that I'd like to define the navbar color from my theme instead of over-riding it.

Nenuial commented 3 weeks ago

This should work for you:

website:
  title: "test-site"
  navbar:
    left: []

in _quarto.yml

joelnitta commented 3 weeks ago

Voilà!

Thanks @Nenuial !

@maelle I think this can now be closed.

Nenuial commented 3 weeks ago

Great news! I'll document this in the page about profiles for future reference.

Maybe there's a better way to do the checks, but I see no obvious way to do it yet (see #69).

I'll close this issue.

maelle commented 3 weeks ago

Yay, a happy ending! Thanks @Nenuial! And thanks @joelnitta for kicking the tires!