From 8657f24da13051ff7a18030007dfa5c08ee26062 Mon Sep 17 00:00:00 2001 From: Martin Lowe Date: Mon, 15 Mar 2021 14:53:58 -0400 Subject: [PATCH] Multilingual support for the testimonials component #165 Added multilingual + multi testimonial set support Signed-off-by: Martin Lowe --- .../content/components/testimonials.es.md | 37 +++++++++++++++++++ .../content/components/testimonials.fr.md | 37 +++++++++++++++++++ .../content/components/testimonials.md | 12 ++++++ .../data/en/localized_testimonials.yml | 10 +++++ .../en/localized_testimonials_no_fallback.yml | 10 +++++ .../data/fr/localized_testimonials.yml | 10 +++++ .../fr/localized_testimonials_no_fallback.yml | 10 +++++ exampleSite/data/localized_testimonials.yml | 10 +++++ exampleSite/data/testimonials.yml | 2 +- layouts/shortcodes/testimonials.html | 11 +++++- 10 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 exampleSite/content/components/testimonials.es.md create mode 100644 exampleSite/content/components/testimonials.fr.md create mode 100644 exampleSite/data/en/localized_testimonials.yml create mode 100644 exampleSite/data/en/localized_testimonials_no_fallback.yml create mode 100644 exampleSite/data/fr/localized_testimonials.yml create mode 100644 exampleSite/data/fr/localized_testimonials_no_fallback.yml create mode 100644 exampleSite/data/localized_testimonials.yml diff --git a/exampleSite/content/components/testimonials.es.md b/exampleSite/content/components/testimonials.es.md new file mode 100644 index 00000000..2eb42491 --- /dev/null +++ b/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" >}} diff --git a/exampleSite/content/components/testimonials.fr.md b/exampleSite/content/components/testimonials.fr.md new file mode 100644 index 00000000..2eb42491 --- /dev/null +++ b/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 **{{< 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" >}} diff --git a/exampleSite/content/components/testimonials.md b/exampleSite/content/components/testimonials.md index f9ed0baa..2eb42491 100644 --- a/exampleSite/content/components/testimonials.md +++ b/exampleSite/content/components/testimonials.md @@ -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" >}} diff --git a/exampleSite/data/en/localized_testimonials.yml b/exampleSite/data/en/localized_testimonials.yml new file mode 100644 index 00000000..f0ed830e --- /dev/null +++ b/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 \ No newline at end of file diff --git a/exampleSite/data/en/localized_testimonials_no_fallback.yml b/exampleSite/data/en/localized_testimonials_no_fallback.yml new file mode 100644 index 00000000..13a36b0b --- /dev/null +++ b/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 \ No newline at end of file diff --git a/exampleSite/data/fr/localized_testimonials.yml b/exampleSite/data/fr/localized_testimonials.yml new file mode 100644 index 00000000..dee89294 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/exampleSite/data/fr/localized_testimonials_no_fallback.yml b/exampleSite/data/fr/localized_testimonials_no_fallback.yml new file mode 100644 index 00000000..b05129f7 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/exampleSite/data/localized_testimonials.yml b/exampleSite/data/localized_testimonials.yml new file mode 100644 index 00000000..47db488b --- /dev/null +++ b/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 \ No newline at end of file diff --git a/exampleSite/data/testimonials.yml b/exampleSite/data/testimonials.yml index e5929476..e8e93fbf 100644 --- a/exampleSite/data/testimonials.yml +++ b/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 diff --git a/layouts/shortcodes/testimonials.html b/layouts/shortcodes/testimonials.html index 8041c7a6..214fcc7f 100644 --- a/layouts/shortcodes/testimonials.html +++ b/layouts/shortcodes/testimonials.html @@ -10,9 +10,18 @@ SPDX-License-Identifier: EPL-2.0 --> + +{{ $source := .Get "source" | default "testimonials" }} +{{ $languageBase := index .Site.Data .Site.Language.Lang }} + +{{ $base := index .Site.Data $source}} +{{ if and (ne $languageBase nil) (isset $languageBase $source) }} + {{ $base = index $languageBase $source }} +{{ end }} +
- {{ range .Site.Data.testimonials.items}} + {{ range $base.items}}

"{{ .text }}"