How do I feature multiple languages for my articles without messing up the navigation? #95

Closed
opened 4 years ago by kolstadmagnus · 5 comments
kolstadmagnus commented 4 years ago (Migrated from github.com)

I’m working on a blog for my studies in journalism. So far, it’s pure HTML & CSS—which is a nightmare to manage, of course. Migrating to Pollen, I’ve now hit a dead end.

Many of my articles are in two languages. (Sort of—it’s two standards of the same language.) I have my main language, Norwegian Bokmål, and then I have a different article in Norwegian Nynorsk available through a link at the beginning of the articles that feature it. However, since I don’t want these translated articles to be a part of the main-language website’s bottom navigation, I don’t include them in the index.ptree file. (I don’t want the user to have to click through to the same article twice—albeit in a different language—when navigating the website.)

Of course, what I then get is an empty navigation bar at the bottom.

I figured I had to create a separate pagetree and template for these translated articles — template-nynorsk.html.p (as opposed to the main template.html.p) and nynorsk.ptree (as opposed to the main index.ptree). For the translated articles’ source files I include a ◊(define-meta template "template-nynorsk.html"). In this template, I include ◊(define-meta pagetree "nynorsk.ptree"). This new pagetree is the same as the old one, but with the articles I’ve translated into Nynorsk instead of the original ones.

This didn’t solve my problem. The Pollen source files can’t find their previous and next articles—even though the new pagetree does feature these source files at localhost:8080/nynorsk.ptree.

What must I do to get the navigation up and running?

(BTW: sincere apologies if the solution already resides somehwere in the Pollen documentation or here on GitHub.)

I’m working on a blog for my studies in journalism. So far, it’s pure HTML & CSS—which is a nightmare to manage, of course. Migrating to Pollen, I’ve now hit a dead end. Many of my articles are in two languages. (Sort of—it’s two standards of the same language.) I have my main language, Norwegian **Bokmål**, and then I have a different article in Norwegian **Nynorsk** available through a link at the beginning of the articles that feature it. However, since I don’t want these translated articles to be a part of the main-language website’s bottom navigation, I don’t include them in the `index.ptree` file. (I don’t want the user to have to click through to the same article twice—albeit in a different language—when navigating the website.) Of course, what I then get is an empty navigation bar at the bottom. I figured I had to create a separate pagetree and template for these translated articles — `template-nynorsk.html.p` (as opposed to the main `template.html.p`) and `nynorsk.ptree` (as opposed to the main `index.ptree`). For the translated articles’ source files I include a `◊(define-meta template "template-nynorsk.html")`. In this template, I include `◊(define-meta pagetree "nynorsk.ptree")`. This new pagetree is the same as the old one, but with the articles I’ve translated into Nynorsk instead of the original ones. This didn’t solve my problem. The Pollen source files can’t find their previous and next articles—even though the new pagetree **does** feature these source files at `localhost:8080/nynorsk.ptree`. What must I do to get the navigation up and running? (BTW: sincere apologies if the solution already resides somehwere in the Pollen documentation or here on GitHub.)
mbutterick commented 4 years ago (Migrated from github.com)

Pollen only recognizes one pagetree at a time (stored in the parameter current-pagetree). So the result here doesn’t surprise me. Your Nyorsk pages are in a pagetree that Pollen never reads. So the built-in pagetree functions like previous and next don’t do anything.

I would go about this a different way. I will assume that in cases where you have a Nyorsk translation, you want the navigation to be the same as the corrresponding Bokmål page. If that is so, then I would:

  1. Use a single template.html.p for all the pages.

  2. Name the Nyorsk pages with some consistent convention. For instance, a Bokmål page "klokken.html" would have a translated version called "klokken-nyorsk.html".

  3. In your template.html.p, create your own previous and next functions.

  4. First, the function will call previous (or next) from pollen/pagetree and see if it gets a valid result. This should be true for all the Bokmål pages, since they are all listed in index.ptree.

  5. But if the result of this function call is #false, then you must be on a Nyorsk page. So derive the name of the corresponding Bokmål page (by operating on here), and call previous (or next) from pollen/pagetree using this Bokmål pagenode. Since all the Bokmål pages are in the pagetree, this should give you the navigation you want.

Alternative #1

You can use parameterize with current-pagetree to change the pagetree to "nyorsk.ptree" when you’re on a Nyorsk page, like so:

(parameterize ([current-pagetree "nyorsk.ptree"])
  (previous here))

This will force previous (or next) to use a different pagetree. This would be useful if you wanted to link all the Nyorsk pages in a parallel navigation scheme. But if my assumption is correct that you want to duplicate the Bokmål navigation, then this approach wouldn’t work.

Alternative #2

In cases where you have a Nyorsk translation, you could nest it inside the existing Bokmål page — thereby eliminating all the Nyorsk-specific source files — and use some other method (e.g. JavaScript) to switch between them. This won’t work if you specifically need a separate URL for the Nyorsk translation.

Pollen only recognizes one pagetree at a time (stored in the parameter `current-pagetree`). So the result here doesn’t surprise me. Your Nyorsk pages are in a pagetree that Pollen never reads. So the built-in pagetree functions like `previous` and `next` don’t do anything. I would go about this a different way. I will assume that in cases where you have a Nyorsk translation, you want the navigation to be the same as the corrresponding Bokmål page. If that is so, then I would: 1. Use a single `template.html.p` for all the pages. 2. Name the Nyorsk pages with some consistent convention. For instance, a Bokmål page `"klokken.html"` would have a translated version called `"klokken-nyorsk.html"`. 3. In your `template.html.p`, create your own `previous` and `next` functions. 4. First, the function will call `previous` (or `next`) from `pollen/pagetree` and see if it gets a valid result. This should be true for all the Bokmål pages, since they are all listed in `index.ptree`. 5. But if the result of this function call is `#false`, then you must be on a Nyorsk page. So derive the name of the corresponding Bokmål page (by operating on `here`), and call `previous` (or `next`) from `pollen/pagetree` using this **Bokmål pagenode**. Since all the Bokmål pages are in the pagetree, this should give you the navigation you want. ### Alternative #1 You can use `parameterize` with `current-pagetree` to change the pagetree to `"nyorsk.ptree"` when you’re on a Nyorsk page, like so: ``` (parameterize ([current-pagetree "nyorsk.ptree"]) (previous here)) ``` This will force `previous` (or `next`) to use a different pagetree. This would be useful if you wanted to link all the Nyorsk pages in a parallel navigation scheme. But if my assumption is correct that you want to duplicate the Bokmål navigation, then this approach wouldn’t work. ### Alternative #2 In cases where you have a Nyorsk translation, you could nest it inside the existing Bokmål page — thereby eliminating all the Nyorsk-specific source files — and use some other method (e.g. JavaScript) to switch between them. This won’t work if you specifically need a separate URL for the Nyorsk translation.
kolstadmagnus commented 4 years ago (Migrated from github.com)

Thank you so much! I ended up choosing alternative #1, as that’s the result I was going for.

Thank you so much! I ended up choosing alternative #1, as that’s the result I was going for.
kolstadmagnus commented 4 years ago (Migrated from github.com)

Before this issue is closed:

When extracting the h1 of a source file to create the HTML <title> for the browser window, I don’t get the full title if I use other tags within the ◊h1.

This title, for example, outputs as only “Creating character:” in my browser window:

◊h1{Creating character: ◊em{The Catcher in the Rye}}

This also happens if I use line breaks within a title:

◊h1{«Nei» til tradisjonell reklame. [line break in Pollen] «Nei» til uavhengig journalistikk?}

(This outputs as “«Nei» til tradisjonell reklame.”)

My template uses the code from the tutorial—◊(select 'h1 doc). Is there a way to solve this using this approach? Or must I use ◊(define-meta title "title-name") and instead extract that in the template, like you do in TFL?

Edit, for clarity: Of course, I don’t ask that italics or line breaks be in the browser window’s title. I only want the whole title to be there, without any formatting.

Before this issue is closed: When extracting the `h1` of a source file to create the HTML `<title>` for the browser window, I don’t get the full title if I use other tags within the `◊h1`. This title, for example, outputs as only “Creating character:” in my browser window: `◊h1{Creating character: ◊em{The Catcher in the Rye}}` This also happens if I use line breaks within a title: `◊h1{«Nei» til tradisjonell reklame.` [line break in Pollen] `«Nei» til uavhengig journalistikk?}` (This outputs as “«Nei» til tradisjonell reklame.”) My template uses the code from the tutorial—`◊(select 'h1 doc)`. Is there a way to solve this using this approach? Or must I use `◊(define-meta title "title-name")` and instead extract that in the template, like you do in TFL? **Edit, for clarity**: Of course, I don’t ask that italics or line breaks be in the browser window’s title. I only want the whole title to be there, without any formatting.
mbutterick commented 4 years ago (Migrated from github.com)

Navigating with an alternative pagetree: I should’ve mentioned that as an alternative to parameterize, you can simply pass the pagetree as a second argument to previous or next, for instance (previous here "nyorsk.ptree") will work the same way.

Generating title text: the problem is that you are using select (which only retrieves the first query result) instead of select* (which you need in this case, because your h1 contains multiple elements). Then you will have to convert these elements into a flat string by whatever means you find suitable (probably by using txexpr functions)

*Navigating with an alternative pagetree:* I should’ve mentioned that as an alternative to `parameterize`, you can simply pass the pagetree as a second argument to `previous` or `next`, for instance `(previous here "nyorsk.ptree")` will work the same way. *Generating title text:* the problem is that you are using `select` (which only retrieves the first query result) instead of `select*` (which you need in this case, because your `h1` contains multiple elements). Then you will have to convert these elements into a flat string by whatever means you find suitable (probably by using `txexpr` functions)
kolstadmagnus commented 4 years ago (Migrated from github.com)

I see. Many thanks!

I see. Many thanks!
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen-users#95
Loading…
There is no content yet.