Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

Multilingual support for the testimonials component #165 #211

Merged
merged 1 commit into from Mar 22, 2021
Merged
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
37 changes: 37 additions & 0 deletions exampleSite/content/components/testimonials.es.md
@@ -0,0 +1,37 @@
---
title: "Testimonials"
date: 2019-04-17T15:52:22-04:00
description: ""
categories: []
keywords: []
slug: ""
aliases: []
toc: false
draft: false
---

You can add testimonials to a markdown file using the shortcode **{{< testimonials >}}**

To add testimonials, create a **testimonials.yml** file in the data folder and add the code below:

~~~~
items:
-
text: Text of the testimonial 1
title: Name of the person
-
text: Text of the testimonial 2
title: Name of the person
~~~~

## Base data source

{{< testimonials >}}

## With localized copies EN + FR, w/ fallback in `./data`

{{< testimonials source="localized_testimonials">}}

## With localized copies EN + FR, w/o fallback in `./data`

{{< testimonials source="localized_testimonials_no_fallback" >}}
37 changes: 37 additions & 0 deletions exampleSite/content/components/testimonials.fr.md
@@ -0,0 +1,37 @@
---
title: "Testimonials"
date: 2019-04-17T15:52:22-04:00
description: ""
categories: []
keywords: []
slug: ""
aliases: []
toc: false
draft: false
---

You can add testimonials to a markdown file using the shortcode **{{&lt; testimonials &gt;}}**

To add testimonials, create a **testimonials.yml** file in the data folder and add the code below:

~~~~
items:
-
text: Text of the testimonial 1
title: Name of the person
-
text: Text of the testimonial 2
title: Name of the person
~~~~

## Base data source

{{< testimonials >}}

## With localized copies EN + FR, w/ fallback in `./data`

{{< testimonials source="localized_testimonials">}}

## With localized copies EN + FR, w/o fallback in `./data`

{{< testimonials source="localized_testimonials_no_fallback" >}}
12 changes: 12 additions & 0 deletions exampleSite/content/components/testimonials.md
Expand Up @@ -23,3 +23,15 @@ items:
text: Text of the testimonial 2
title: Name of the person
~~~~

## Base data source

{{< testimonials >}}

## With localized copies EN + FR, w/ fallback in `./data`

{{< testimonials source="localized_testimonials">}}

## With localized copies EN + FR, w/o fallback in `./data`

{{< testimonials source="localized_testimonials_no_fallback" >}}
10 changes: 10 additions & 0 deletions exampleSite/data/en/localized_testimonials.yml
@@ -0,0 +1,10 @@
items:
-
text: Text of the testimonial 1(localized, en)
title: Name of the person
-
text: Text of the testimonial 2
title: Name of the person
-
text: Text of the testimonial 3
title: Name of the person
10 changes: 10 additions & 0 deletions exampleSite/data/en/localized_testimonials_no_fallback.yml
@@ -0,0 +1,10 @@
items:
-
text: Text of the testimonial 1(localized no fallback, en)
title: Name of the person
-
text: Text of the testimonial 2
title: Name of the person
-
text: Text of the testimonial 3
title: Name of the person
10 changes: 10 additions & 0 deletions exampleSite/data/fr/localized_testimonials.yml
@@ -0,0 +1,10 @@
items:
-
text: Text of the testimonial 1(localized, fr)
title: Name of the person
-
text: Text of the testimonial 2
title: Name of the person
-
text: Text of the testimonial 3
title: Name of the person
10 changes: 10 additions & 0 deletions exampleSite/data/fr/localized_testimonials_no_fallback.yml
@@ -0,0 +1,10 @@
items:
-
text: Text of the testimonial 1(localized no fallback, fr)
title: Name of the person
-
text: Text of the testimonial 2
title: Name of the person
-
text: Text of the testimonial 3
title: Name of the person
10 changes: 10 additions & 0 deletions exampleSite/data/localized_testimonials.yml
@@ -0,0 +1,10 @@
items:
-
text: Text of the testimonial 1 (localized backup, no lang)
title: Name of the person
-
text: Text of the testimonial 2
title: Name of the person
-
text: Text of the testimonial 3
title: Name of the person
2 changes: 1 addition & 1 deletion exampleSite/data/testimonials.yml
@@ -1,6 +1,6 @@
items:
-
text: Text of the testimonial 1
text: Text of the testimonial 1 (loc data/testimonials.yml)
title: Name of the person
-
text: Text of the testimonial 2
Expand Down
11 changes: 10 additions & 1 deletion layouts/shortcodes/testimonials.html
Expand Up @@ -10,9 +10,18 @@

SPDX-License-Identifier: EPL-2.0
-->
<!-- Allow for alt sources and languages -->
{{ $source := .Get "source" | default "testimonials" }}
{{ $languageBase := index .Site.Data .Site.Language.Lang }}
<!-- Get the base of the testimonials by checking existence in localized section -->
{{ $base := index .Site.Data $source}}
{{ if and (ne $languageBase nil) (isset $languageBase $source) }}
{{ $base = index $languageBase $source }}
{{ end }}


<div class="row testimonial-container">
{{ range .Site.Data.testimonials.items}}
{{ range $base.items}}
<div class="col-sm-8 margin-bottom-20 testimonial-item">
<div style="background-color:#f1f3f7;" class="padding-20">
<p>"{{ .text }}"</p>
Expand Down