From 6d6f96c15aa7644a6827082fd56f6d4e0be8fcb1 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Wed, 28 Jul 2021 20:03:23 +0800 Subject: [PATCH] feat: new framework jeklly support, close #568 --- .../jekyll/.vscode/settings.json | 3 ++ examples/by-frameworks/jekyll/Gemfile | 4 +++ examples/by-frameworks/jekyll/LICENSE | 21 ++++++++++++ examples/by-frameworks/jekyll/_i18n/en.yml | 3 ++ examples/by-frameworks/jekyll/_i18n/fr.yml | 3 ++ examples/by-frameworks/jekyll/_pages/404.html | 13 ++++++++ package.json | 3 +- src/frameworks/index.ts | 2 ++ src/frameworks/jekyll.ts | 32 +++++++++++++++++++ 9 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 examples/by-frameworks/jekyll/.vscode/settings.json create mode 100644 examples/by-frameworks/jekyll/Gemfile create mode 100644 examples/by-frameworks/jekyll/LICENSE create mode 100644 examples/by-frameworks/jekyll/_i18n/en.yml create mode 100644 examples/by-frameworks/jekyll/_i18n/fr.yml create mode 100644 examples/by-frameworks/jekyll/_pages/404.html create mode 100644 src/frameworks/jekyll.ts diff --git a/examples/by-frameworks/jekyll/.vscode/settings.json b/examples/by-frameworks/jekyll/.vscode/settings.json new file mode 100644 index 00000000..efbb9b8b --- /dev/null +++ b/examples/by-frameworks/jekyll/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "i18n-ally.localesPaths": ["_i18n"] +} diff --git a/examples/by-frameworks/jekyll/Gemfile b/examples/by-frameworks/jekyll/Gemfile new file mode 100644 index 00000000..2bc08c27 --- /dev/null +++ b/examples/by-frameworks/jekyll/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'jekyll', github: 'jekyll/jekyll' +gem 'jekyll-multiple-languages-plugin' diff --git a/examples/by-frameworks/jekyll/LICENSE b/examples/by-frameworks/jekyll/LICENSE new file mode 100644 index 00000000..7fade556 --- /dev/null +++ b/examples/by-frameworks/jekyll/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Dorian OUAKLI + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/examples/by-frameworks/jekyll/_i18n/en.yml b/examples/by-frameworks/jekyll/_i18n/en.yml new file mode 100644 index 00000000..b925734a --- /dev/null +++ b/examples/by-frameworks/jekyll/_i18n/en.yml @@ -0,0 +1,3 @@ +four_hundred_four: + page_not_found: Page not found :( + turn_back_home: Go back home diff --git a/examples/by-frameworks/jekyll/_i18n/fr.yml b/examples/by-frameworks/jekyll/_i18n/fr.yml new file mode 100644 index 00000000..449f222c --- /dev/null +++ b/examples/by-frameworks/jekyll/_i18n/fr.yml @@ -0,0 +1,3 @@ +four_hundred_four: + page_not_found: Page non trouvée :( + turn_back_home: Retourner à l'accueil diff --git a/examples/by-frameworks/jekyll/_pages/404.html b/examples/by-frameworks/jekyll/_pages/404.html new file mode 100644 index 00000000..f74a5a9b --- /dev/null +++ b/examples/by-frameworks/jekyll/_pages/404.html @@ -0,0 +1,13 @@ +--- +layout: default +not_in_footer: true +ref: four_hundred_four +--- + +
+
+

404

+

{% t four_hundred_four.page_not_found %}

+

{% t four_hundred_four.turn_back_home %}

+
+
diff --git a/package.json b/package.json index cd2d5fca..4a8f37c3 100644 --- a/package.json +++ b/package.json @@ -814,7 +814,8 @@ "next-translate", "php-gettext", "general", - "lingui" + "lingui", + "jekyll" ] }, "description": "%config.enabled_frameworks%" diff --git a/src/frameworks/index.ts b/src/frameworks/index.ts index f03a9d63..28714980 100644 --- a/src/frameworks/index.ts +++ b/src/frameworks/index.ts @@ -24,6 +24,7 @@ import NextTranslateFramework from './next-translate' import PhpGettextFramework from './php-gettext' import GeneralFramework from './general' import LinguiFramework from './lingui' +import JekyllFramework from './jekyll' import i18n from '~/i18n' import { Log } from '~/utils' @@ -55,6 +56,7 @@ export const frameworks: Framework[] = [ new NextTranslateFramework(), new PhpGettextFramework(), new LinguiFramework(), + new JekyllFramework(), new GeneralFramework(), // Vue SFC should be the last one diff --git a/src/frameworks/jekyll.ts b/src/frameworks/jekyll.ts new file mode 100644 index 00000000..a3b94128 --- /dev/null +++ b/src/frameworks/jekyll.ts @@ -0,0 +1,32 @@ +import { Framework } from './base' +import { LanguageId } from '~/utils' + +class JekyllFramework extends Framework { + id = 'jekyll' + display = 'Jekyll' + + detection = { + gemfile: [ + 'jekyll-multiple-languages-plugin', + ], + } + + languageIds: LanguageId[] = [ + 'html', + ] + + usageMatchRegex = [ + '\\{\\%\\s+t\\s+({key})\\s+\\%\\}', + ] + + perferredKeystyle = 'nested' as const + + refactorTemplates(keypath: string) { + return [ + `{% t ${keypath} %}`, + keypath, + ] + } +} + +export default JekyllFramework