@pcdevil/eleventy-plugin-intl-utils 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +32 -16
- package/README.md +37 -17
- package/package.json +24 -14
- package/src/eleventy-plugin-intl-utils.mjs +16 -0
- package/src/filters/{country_name.js → country_name.mjs} +1 -5
- package/src/filters/{language_name.js → language_name.mjs} +1 -5
- package/src/filters/{short_datetime_format.js → short_datetime_format.mjs} +1 -5
- package/src/shortcodes/{year_interval.js → year_interval.mjs} +1 -5
- package/src/shortcodes/{year_open_interval.js → year_open_interval.mjs} +1 -5
- package/.prettierrc.json +0 -11
- package/src/eleventy.js +0 -18
package/LICENSE.md
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 3-Clause BSD NON-AI License
|
|
2
2
|
|
|
3
|
-
Copyright
|
|
3
|
+
Copyright 2023-, Attila Gonda https://attilagonda.com
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
the Software without restriction, including without limitation the rights to
|
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
-
subject to the following conditions:
|
|
5
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
6
|
+
are permitted provided that the following conditions are met:
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
16
|
+
may be used to endorse or promote products derived from this software without
|
|
17
|
+
specific prior written permission.
|
|
18
|
+
|
|
19
|
+
4. The source code and the binary form, and any modifications made to them may
|
|
20
|
+
not be used for the purpose of training or improving machine learning
|
|
21
|
+
algorithms, including but not limited to artificial intelligence, natural
|
|
22
|
+
language processing, or data mining. This condition applies to any
|
|
23
|
+
derivatives, modifications, or updates based on the Software code. Any usage
|
|
24
|
+
of the source code or the binary form in an AI-training dataset is considered
|
|
25
|
+
a breach of this License.
|
|
26
|
+
|
|
27
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
28
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
29
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
30
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
31
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
32
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
33
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
34
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
35
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
36
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
# eleventy-plugin-intl-utils
|
|
1
|
+
# eleventy-plugin-intl-utils <a href="https://ko-fi.com/s/4662b19f61"><img src="assets/made-by-a-human_badge.png"></a>
|
|
2
|
+
|
|
2
3
|
A set of internationalization utils for [Eleventy](https://www.11ty.dev/).
|
|
3
4
|
|
|
5
|
+
💙 This project is made by humans for humans - using it with LLM models is strongly discouraged: the [AGENTS.md](AGENTS.md) and [CLAUDE.md](CLAUDE.md) files only exist to instruct such tools to halt any action.
|
|
6
|
+
|
|
4
7
|
## Motivation
|
|
8
|
+
|
|
5
9
|
It's super fast to create a static website with **Eleventy** and with the help of [`eleventy-plugin-i18n`](https://www.npmjs.com/package/eleventy-plugin-i18n) localization can be done with ease too.
|
|
6
10
|
|
|
7
11
|
However it only gives solution for static data and dynamic data still needs treatment during layout rendering. This plugin aims to help with a set of [filters](https://www.11ty.dev/docs/filters/) and [shortcodes](https://www.11ty.dev/docs/shortcodes/).
|
|
@@ -9,32 +13,34 @@ However it only gives solution for static data and dynamic data still needs trea
|
|
|
9
13
|
The implementations of the filters are mostly wrappers around the [ECMAScript Internationalization API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) with a little _bit of sugar_.
|
|
10
14
|
|
|
11
15
|
## Usage
|
|
16
|
+
|
|
12
17
|
This guide corresponds to [Eleventy documentation](https://www.11ty.dev/docs/plugins/#add-the-plugin-to-eleventy-in-your-config-file):
|
|
13
18
|
|
|
14
19
|
1. Install the package
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
```bash
|
|
21
|
+
npm install --save @pcdevil/eleventy-plugin-intl-utils
|
|
22
|
+
```
|
|
18
23
|
|
|
19
24
|
2. Add to your config file
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
```javascript
|
|
26
|
+
// file: eleventy.config.js
|
|
27
|
+
import intlUtils from '@pcdevil/eleventy-plugin-intl-utils';
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
export default async function (eleventyConfig) {
|
|
30
|
+
// ...
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```
|
|
32
|
+
eleventyConfig.addPlugin(intlUtils, {
|
|
33
|
+
locale: 'en-GB',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
```
|
|
33
37
|
|
|
34
38
|
## Configuration object
|
|
39
|
+
|
|
35
40
|
A general configuration object can be passed optionally via Eleventy config when the plugin is initiated. This sections lists the available configuration properties.
|
|
36
41
|
|
|
37
42
|
### `locale`
|
|
43
|
+
|
|
38
44
|
This property affects the output language of the filters. See [`locales` argument section on Intl page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument) for more info.
|
|
39
45
|
|
|
40
46
|
- **Type**: String
|
|
@@ -44,6 +50,7 @@ This property affects the output language of the filters. See [`locales` argumen
|
|
|
44
50
|
## Filters
|
|
45
51
|
|
|
46
52
|
### `country_name`
|
|
53
|
+
|
|
47
54
|
Transforms a country code into a country name. Useful to display author's location.
|
|
48
55
|
|
|
49
56
|
- **Used Internationalization API**: `Intl.DisplayNames()` with _region_ type ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames))
|
|
@@ -58,6 +65,7 @@ Transforms a country code into a country name. Useful to display author's locati
|
|
|
58
65
|
This renders "France" when the `intlUtilConfig.locale` is `en`.
|
|
59
66
|
|
|
60
67
|
### `language_name`
|
|
68
|
+
|
|
61
69
|
Transforms a language code to a renderable text. Useful for language selectors or when the current language is displayed.
|
|
62
70
|
|
|
63
71
|
- **Used Internationalization API**: `Intl.DisplayNames()` with _language_ type ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#using_type_language_with_languagedisplay))
|
|
@@ -72,6 +80,7 @@ Transforms a language code to a renderable text. Useful for language selectors o
|
|
|
72
80
|
This renders "British English" when the `intlUtilConfig.locale` is `en`.
|
|
73
81
|
|
|
74
82
|
### `short_datetime_format`
|
|
83
|
+
|
|
75
84
|
Transforms a date string to a short date time text. Useful for blog post dates.
|
|
76
85
|
|
|
77
86
|
- **Used Internationalization API**: `Intl.DateTimeFormat()` with _short_ date and time style ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat))
|
|
@@ -88,6 +97,7 @@ This renders "12/12/21, 5:36 PM" when the `intlUtilConfig.locale` is `en`.
|
|
|
88
97
|
## Shortcodes
|
|
89
98
|
|
|
90
99
|
### `year_interval`
|
|
100
|
+
|
|
91
101
|
Transforms two date strings to a year range. Useful when a larger time interval is presented.
|
|
92
102
|
|
|
93
103
|
The input should be an array with two date string and the first one should precede before the second one.
|
|
@@ -105,6 +115,7 @@ The input should be an array with two date string and the first one should prece
|
|
|
105
115
|
This renders "2011 – 2020" (with en dash in the middle) when the `intlUtilConfig.locale` is `en`.
|
|
106
116
|
|
|
107
117
|
#### Fallback value
|
|
118
|
+
|
|
108
119
|
The second `endDate` argument can be omitted and it has the current date as default value.
|
|
109
120
|
|
|
110
121
|
This behaviour helps when an open-ended / ongoing interval needs be displayed:
|
|
@@ -117,6 +128,7 @@ This behaviour helps when an open-ended / ongoing interval needs be displayed:
|
|
|
117
128
|
This renders "2011 – 2021" (with en dash in the middle) when the `intlUtilConfig.locale` is `en` and the current year is 2021.
|
|
118
129
|
|
|
119
130
|
### `year_open_interval`
|
|
131
|
+
|
|
120
132
|
Transforms a date string into an _open_ year range where the end date is absent. Useful when a ongoing interval is presented.
|
|
121
133
|
|
|
122
134
|
- **Used Internationalization API**: `Intl.DateTimeFormat.prototype.formatRange()` with _numeric_ year ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange))
|
|
@@ -131,7 +143,15 @@ Transforms a date string into an _open_ year range where the end date is absent.
|
|
|
131
143
|
This renders "2011 – " (with en dash in the middle) when the `intlUtilConfig.locale` is `en`.
|
|
132
144
|
|
|
133
145
|
#### Difference from `year_interval`
|
|
146
|
+
|
|
134
147
|
While the [`year_interval`](#year_interval) shortcode always created a _closed_ year range (by applying the current year as default), the `year_open_interval` only displays the start date.
|
|
135
148
|
|
|
136
|
-
## License
|
|
137
|
-
|
|
149
|
+
## License and acknowledgments
|
|
150
|
+
|
|
151
|
+
The project is available under the **3-Clause BSD** license with an extension of prohibiting to use it with Gen-AI and LLMs tools, see the [LICENSE.md](LICENSE.md) file.
|
|
152
|
+
|
|
153
|
+
"Human made content badge" badge created by **Andy Carolan**: <https://www.andycarolan.com/>
|
|
154
|
+
|
|
155
|
+
License based on **Aleksandar Prokopec**'s Non-AI Licenses: <https://github.com/non-ai-licenses/non-ai-licenses>
|
|
156
|
+
|
|
157
|
+
`AGENTS.md` is created by **Alice D.**: <https://codeberg.org/queer-computer-club/doorbot/src/branch/doorbot-pro-max-ultra-deluxe-se/AGENTS.md>
|
package/package.json
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pcdevil/eleventy-plugin-intl-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"description": "A set of internationalization utils for Eleventy.",
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": "
|
|
10
|
+
"node": "^22.23.1",
|
|
11
|
+
"npm": "^10.9.8"
|
|
11
12
|
},
|
|
12
|
-
"
|
|
13
|
+
"packageManager": "npm@10.9.8",
|
|
14
|
+
"main": "./src/eleventy-plugin-intl-utils.mjs",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"files": [
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
13
19
|
"scripts": {
|
|
14
|
-
"format": "
|
|
15
|
-
"format:
|
|
16
|
-
"lint": "
|
|
17
|
-
"lint:
|
|
20
|
+
"format": "dprint fmt",
|
|
21
|
+
"format:check-only": "dprint check",
|
|
22
|
+
"lint": "eslint --fix",
|
|
23
|
+
"lint:check-only": "eslint",
|
|
18
24
|
"release:major": "npm version major",
|
|
19
25
|
"release:minor": "npm version minor",
|
|
20
|
-
"release:patch": "npm version patch"
|
|
26
|
+
"release:patch": "npm version patch",
|
|
27
|
+
"update:dprint-plugins": "dprint config update"
|
|
21
28
|
},
|
|
22
29
|
"repository": {
|
|
23
30
|
"type": "git",
|
|
24
|
-
"url": "
|
|
31
|
+
"url": "https://codeberg.org/pcdevil/eleventy-plugin-intl-utils.git"
|
|
25
32
|
},
|
|
26
33
|
"keywords": [
|
|
27
34
|
"11ty",
|
|
@@ -36,13 +43,16 @@
|
|
|
36
43
|
"name": "Attila Gonda",
|
|
37
44
|
"url": "https://attilagonda.com"
|
|
38
45
|
},
|
|
39
|
-
"license": "
|
|
46
|
+
"license": "BSD-3-Clause-NO-AI",
|
|
40
47
|
"bugs": {
|
|
41
|
-
"url": "https://
|
|
48
|
+
"url": "https://codeberg.org/pcdevil/eleventy-plugin-intl-utils/issues"
|
|
42
49
|
},
|
|
43
|
-
"homepage": "https://
|
|
50
|
+
"homepage": "https://codeberg.org/pcdevil/eleventy-plugin-intl-utils",
|
|
44
51
|
"devDependencies": {
|
|
45
|
-
"eslint": "
|
|
46
|
-
"
|
|
52
|
+
"@eslint/config-helpers": "~0.6.0",
|
|
53
|
+
"@eslint/js": "^10.0.1",
|
|
54
|
+
"dprint": "~0.55.1",
|
|
55
|
+
"eslint": "^10.6.0",
|
|
56
|
+
"globals": "^17.7.0"
|
|
47
57
|
}
|
|
48
58
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { countryNameFactory } from './filters/country_name.mjs';
|
|
2
|
+
import { languageNameFactory } from './filters/language_name.mjs';
|
|
3
|
+
import { shortDateTimeFormatFactory } from './filters/short_datetime_format.mjs';
|
|
4
|
+
import { yearIntervalFactory } from './shortcodes/year_interval.mjs';
|
|
5
|
+
import { yearOpenIntervalFactory } from './shortcodes/year_open_interval.mjs';
|
|
6
|
+
|
|
7
|
+
export default function eleventyPluginIntlUtils (eleventyConfig, pluginConfig = {}) {
|
|
8
|
+
const { locale } = pluginConfig;
|
|
9
|
+
|
|
10
|
+
eleventyConfig.addFilter('country_name', countryNameFactory(locale));
|
|
11
|
+
eleventyConfig.addFilter('language_name', languageNameFactory(locale));
|
|
12
|
+
eleventyConfig.addFilter('short_datetime_format', shortDateTimeFormatFactory(locale));
|
|
13
|
+
|
|
14
|
+
eleventyConfig.addShortcode('year_interval', yearIntervalFactory(locale));
|
|
15
|
+
eleventyConfig.addShortcode('year_open_interval', yearOpenIntervalFactory(locale));
|
|
16
|
+
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function countryNameFactory(locale) {
|
|
1
|
+
export function countryNameFactory (locale) {
|
|
4
2
|
const displayName = new Intl.DisplayNames([locale], { type: 'region' });
|
|
5
3
|
|
|
6
4
|
return (countryCode) => displayName.of(countryCode);
|
|
7
5
|
}
|
|
8
|
-
|
|
9
|
-
module.exports = countryNameFactory;
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function languageNameFactory(locale) {
|
|
1
|
+
export function languageNameFactory (locale) {
|
|
4
2
|
const displayName = new Intl.DisplayNames([locale], { type: 'language' });
|
|
5
3
|
|
|
6
4
|
return (language) => displayName.of(language);
|
|
7
5
|
}
|
|
8
|
-
|
|
9
|
-
module.exports = languageNameFactory;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function shortDateTimeFormatFactory(locale) {
|
|
1
|
+
export function shortDateTimeFormatFactory (locale) {
|
|
4
2
|
const dateTimeFormat = new Intl.DateTimeFormat(locale, {
|
|
5
3
|
dateStyle: 'short',
|
|
6
4
|
timeStyle: 'short',
|
|
@@ -8,5 +6,3 @@ function shortDateTimeFormatFactory(locale) {
|
|
|
8
6
|
|
|
9
7
|
return (date) => dateTimeFormat.format(new Date(date));
|
|
10
8
|
}
|
|
11
|
-
|
|
12
|
-
module.exports = shortDateTimeFormatFactory;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function yearIntervalFactory(locale) {
|
|
1
|
+
export function yearIntervalFactory (locale) {
|
|
4
2
|
const dateTimeFormat = new Intl.DateTimeFormat(locale, {
|
|
5
3
|
year: 'numeric',
|
|
6
4
|
});
|
|
7
5
|
|
|
8
6
|
return (startDate, endDate = new Date()) => dateTimeFormat.formatRange(new Date(startDate), new Date(endDate));
|
|
9
7
|
}
|
|
10
|
-
|
|
11
|
-
module.exports = yearIntervalFactory;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function yearOpenIntervalFactory(locale) {
|
|
1
|
+
export function yearOpenIntervalFactory (locale) {
|
|
4
2
|
const dateTimeFormat = new Intl.DateTimeFormat(locale, {
|
|
5
3
|
year: 'numeric',
|
|
6
4
|
});
|
|
@@ -12,5 +10,3 @@ function yearOpenIntervalFactory(locale) {
|
|
|
12
10
|
.map(({ value }) => value)
|
|
13
11
|
.join('');
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
module.exports = yearOpenIntervalFactory;
|
package/.prettierrc.json
DELETED
package/src/eleventy.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const countryNameFactory = require('./filters/country_name');
|
|
4
|
-
const languageNameFactory = require('./filters/language_name');
|
|
5
|
-
const shortDateTimeFormatFactory = require('./filters/short_datetime_format');
|
|
6
|
-
const yearIntervalFactory = require('./shortcodes/year_interval');
|
|
7
|
-
const yearOpenIntervalFactory = require('./shortcodes/year_open_interval');
|
|
8
|
-
|
|
9
|
-
module.exports = (eleventyConfig, pluginConfig = {}) => {
|
|
10
|
-
const { locale } = pluginConfig;
|
|
11
|
-
|
|
12
|
-
eleventyConfig.addFilter('country_name', countryNameFactory(locale));
|
|
13
|
-
eleventyConfig.addFilter('language_name', languageNameFactory(locale));
|
|
14
|
-
eleventyConfig.addFilter('short_datetime_format', shortDateTimeFormatFactory(locale));
|
|
15
|
-
|
|
16
|
-
eleventyConfig.addShortcode('year_interval', yearIntervalFactory(locale));
|
|
17
|
-
eleventyConfig.addShortcode('year_open_interval', yearOpenIntervalFactory(locale));
|
|
18
|
-
};
|