Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use Eleventy localization features and Eleventy asset processing #337

Merged
merged 53 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
be66e78
feat: use Eleventy localization features
greatislander Jul 28, 2023
a480158
Merge branch 'main' into feat/native-localization
greatislander Jul 31, 2023
64dc6a0
feat: use JavaScript templating more completely in generatePermalink
greatislander Jul 31, 2023
b8e3b4f
feat: add global defaultLanguageDirection data
greatislander Jul 31, 2023
a0789ba
feat: migrate some language functionality to eleventy-plugin-fluid
greatislander Aug 1, 2023
5a49111
chore(deps): bump eleventy-plugin-fluid to 2.0.0
greatislander Aug 2, 2023
d323f9c
feat: use generic YAML file for CMS config (fix #242)
greatislander Aug 2, 2023
be8b595
feat: simplify configuration, use default build directory
greatislander Aug 2, 2023
b596a8d
feat: prefix build helper directories with underscore
greatislander Aug 2, 2023
7b0cf85
feat: use local versions of CMS dependencies
greatislander Aug 2, 2023
f70da4d
chore(deps): bump eleventy-plugin-fluid to 2.1.0
greatislander Aug 2, 2023
2e4e0a3
feat: split linting into separate tasks
greatislander Aug 2, 2023
b8a37d4
feat: split linting into separate tasks
greatislander Aug 2, 2023
eb87a7d
feat: prefix locales directory with underscore, adjust Dockerfile
greatislander Aug 2, 2023
5112150
fix: adjust config
greatislander Aug 2, 2023
9ed7b46
fix: adjust Netlify config
greatislander Aug 2, 2023
ad37c42
chore(docs): update README
greatislander Aug 2, 2023
5e346a3
chore(docs): document how to disable internationalization for a colle…
greatislander Aug 3, 2023
b6cd796
chore(docs): document how to disable internationalization for the ent…
greatislander Aug 3, 2023
c69300e
chore(deps): bump eleventy-plugin-fluid to 2.3.0
greatislander Aug 3, 2023
a1c2f8f
chore(docs): remove Laravel Mix and dist directory references
greatislander Aug 4, 2023
91ba199
fix: resolve issue with French configuration and asset paths
greatislander Aug 4, 2023
2e20419
chore: clean up assets folders
greatislander Aug 4, 2023
ee04478
chore(docs): fix typo
greatislander Aug 4, 2023
5f4a377
fix: improve support for non-localized collections
greatislander Aug 4, 2023
6ad015a
chore(docs): clarify modifications to collections directories
greatislander Aug 4, 2023
ece38d7
chore(docs): add heading for 'Adding a language'
greatislander Aug 4, 2023
fb15745
chore(deps): bump eleventy-plugin-fluid to 2.3.1
greatislander Aug 4, 2023
776dcfd
chore(docs): document locale-specific 11tydata.js files
greatislander Aug 4, 2023
8ed51a1
fix: simplify collection configuration
greatislander Aug 4, 2023
ae09653
feat: add alternate link in head
greatislander Aug 4, 2023
b90f135
fix: correct ignore pattern for markdownlint
greatislander Aug 4, 2023
1277b9b
feat: add YAML linting
greatislander Aug 4, 2023
e824391
fix: add Netlify Identity widget to home page
greatislander Aug 4, 2023
5cef95d
chore(docs): document removal of string localization from feed
greatislander Aug 4, 2023
6a4056f
fix: update sitemap to handle new localization system
greatislander Aug 4, 2023
01f09bc
ci: split workflows
greatislander Aug 4, 2023
4bfe968
ci: split workflows
greatislander Aug 4, 2023
84e30cc
chore(deps): updated Dependabot configuration
greatislander Aug 4, 2023
4c00f38
ci: remove redundant workflow
greatislander Aug 4, 2023
e956fa4
chore(docs): add details to language addition and localized index rem…
greatislander Aug 8, 2023
d036fb2
chore(docs): remove outdated import from README
greatislander Aug 8, 2023
6e952a4
chore(docs): document removing post indexes and feed for all languages
greatislander Aug 8, 2023
2516a31
chore(docs): update instructions for disabling localization in a coll…
greatislander Aug 8, 2023
fa54542
fix: remove unused passthrough copy rule
greatislander Aug 8, 2023
4816585
chore(docs): clarify reference to earlier step
greatislander Aug 8, 2023
19a20c3
chore(docs): update docs to reflect new approach to starting projects…
greatislander Aug 9, 2023
785285c
chore(docs): remove extra step from advanced de-localization method
greatislander Aug 9, 2023
1ebcfbb
feat: add debug script
greatislander Aug 9, 2023
15b9a4e
feat: standardize scripts
greatislander Aug 9, 2023
44ffbd5
chore(docs): fix instructions for disabling collection locale
greatislander Aug 10, 2023
e8ad92d
Merge branch 'main' into feat/native-localization
greatislander Aug 10, 2023
204b185
chore(docs): fix typo in code example
greatislander Aug 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist/**
!.eleventy.js
locales/message.js
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"es6": true
},
"parserOptions": {
"ecmaVersion": 8
"ecmaVersion": 2020
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
**/.DS_Store
node_modules
dist
src/_data/assets.json
4 changes: 4 additions & 0 deletions .husky/commit-message
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,12 @@ following changes need to be made:
to the [IETF language code](https://github.com/unicode-org/cldr-json/blob/master/cldr-json/cldr-core/availableLocales.json)
of the desired default language.

2. Add sections for the new language to [`src/_data/site.json`](src/_data/site.json) and [`src/_data/translations.json`](src/_data/translations.json),
translating the content from the English source. The key will always be the language code as used in `config.json`.
2. Add a section for the new language to [`src/_data/site.json`](src/_data/site.json), translating the content from the
English source. The key will always be the language code as used in `config.json`.
3. Add folders in each collection for translated content. For example, you would add a folder called `fa-IR` to
[`src/collections/pages`](src/collections/pages) and [`src/collections/posts`](src/collections/posts).
4. Create a localized version of the posts archive page, following the example of [`src/posts.fr-CA.md`](src/posts.fr-CA.md).
(Note: as per Eleventy's [default configuration](https://www.11ty.dev/docs/config/#default-template-engine-for-markdown-files),
Markdown files are processed with the Liquid template language. If for some reason one decides to modify this to use
Nunjucks or another template language, the permalink syntax in all post archive pages will need to be modified to use
the chosen template language.)
5. Create a localized version of the 404 page, following the example of [`src/404.fr-CA.md`](src/404.fr-CA.md).
(Note: as per Eleventy's [default configuration](https://www.11ty.dev/docs/config/#default-template-engine-for-markdown-files),
Markdown files are processed with the Liquid template language. If for some reason one decides to modify this to use
Nunjucks or another template language, the permalink syntax in all post archive pages will need to be modified to use
the chosen template language.)
4. Create a localized version of the posts archive page, following the example of [`src/collections/pages/fr-CA/posts.md`](src/collections/pages/fr-CA/posts.md).
5. Create a localized version of the 404 page, following the example of [`src/collections/pages/fr-CA/404.fr.md`](src/collections/pages/fr-CA/404.fr.md).
6. To ensure that the 404 page is displayed in the appropriate language, verify that a redirect block has been added to
the [netlify.toml](netlify.toml) file for each language following the examples. This feature is described in
Netlify's [redirects documentation](https://docs.netlify.com/routing/redirects/redirect-options/#custom-404-page-handling).
Expand Down
38 changes: 10 additions & 28 deletions .eleventy.js → eleventy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ https://github.com/fluid-project/trivet/raw/main/LICENSE.md.

"use strict";

const fs = require("fs");

const fluidPlugin = require("eleventy-plugin-fluid");
const { EleventyI18nPlugin } = require("@11ty/eleventy");
const i18n = require("eleventy-plugin-i18n-gettext");
const navigationPlugin = require("@11ty/eleventy-navigation");
const rssPlugin = require("@11ty/eleventy-plugin-rss");
const syntaxHighlightPlugin = require("@11ty/eleventy-plugin-syntaxhighlight");

// Import transforms
const htmlMinTransform = require("./src/transforms/html-min-transform.js");
const parseTransform = require("./src/transforms/parse-transform.js");

// Import data files
Expand All @@ -30,7 +29,6 @@ module.exports = function (config) {
config.setUseGitIgnore(false);

// Transforms
config.addTransform("htmlmin", htmlMinTransform);
config.addTransform("parse", parseTransform);

// Passthrough copy
Expand Down Expand Up @@ -58,39 +56,23 @@ module.exports = function (config) {

// Plugins
config.addPlugin(fluidPlugin);
config.addPlugin(EleventyI18nPlugin, {
defaultLanguage: "en-CA"
});
config.addGlobalData("defaultLanguage", "en-CA");
config.addGlobalData("defaultLanguageDirection", "ltr");
config.addPlugin(i18n);
config.addPlugin(navigationPlugin);
config.addPlugin(rssPlugin);
config.addPlugin(syntaxHighlightPlugin);

// 404
config.setBrowserSyncConfig({
callbacks: {
ready: function (err, bs) {

bs.addMiddleware("*", (req, res) => {
const content_404 = fs.readFileSync("dist/404.html");
// Provides the 404 content without redirect.
res.write(content_404);
res.writeHead(404);
res.end();
});
}
}
});

config.on("beforeBuild", () => {
if (!siteConfig.languages[siteConfig.defaultLanguage]) {
process.exitCode = 1;
throw new Error(`The default language, ${siteConfig.defaultLanguage}, configured in src/_data/config.json is not one of your site's supported languages.`);
}
});

return {
dir: {
input: "src",
output: "dist",
includes: "_includes"
},
passthroughFileCopy: true
passthroughFileCopy: true,
markdownTemplateEngine: "njk"
};
};
Binary file added locales/fr-CA/messages.mo
Binary file not shown.
33 changes: 33 additions & 0 deletions locales/fr-CA/messages.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2023-07-28 11:41-0300\n"
"PO-Revision-Date: 2023-07-28 11:41-0300\n"
"Last-Translator: OCAD University <idrc@ocadu.ca>\n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.3.1\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-KeywordsList: _n:1,2;_i\n"
"X-Poedit-SearchPath-0: messages.js\n"

#: messages.js:3
#, javascript-format
msgid "%s RSS feed"
msgstr "Flux RSS %s"

#: messages.js:4
msgid "menu"
msgstr "menu"

#: messages.js:5
#, javascript-format
msgid "The most recent posts from %s"
msgstr "Les articles les plus récents de %s"

#: messages.js:6
msgid "posts"
msgstr "articles"
6 changes: 6 additions & 0 deletions locales/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// WARNING! This file is generated by a tool.
// It exists only to allow PO editors to get translation keys from source code.
_("%s RSS feed")
_("menu")
_("The most recent posts from %s")
_("posts")
Loading
Loading