@pcdevil/eleventy-plugin-intl-utils 1.1.0 → 2.0.1

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 CHANGED
@@ -1,20 +1,36 @@
1
- # The MIT License
1
+ # 3-Clause BSD NON-AI License
2
2
 
3
- Copyright 2021 Attila Gonda https://attilagonda.com
3
+ Copyright 2023-, Attila Gonda https://attilagonda.com
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
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
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
14
10
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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,52 +1,76 @@
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
6
+ strongly discouraged: the [AGENTS.md](AGENTS.md) and [CLAUDE.md](CLAUDE.md)
7
+ files only exist to instruct such tools to halt any action.
8
+
4
9
  ## Motivation
5
- 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
- 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/).
11
+ It's super fast to create a static website with **Eleventy** and with the help
12
+ of [`eleventy-plugin-i18n`](https://www.npmjs.com/package/eleventy-plugin-i18n)
13
+ localization can be done with ease too.
14
+
15
+ However it only gives solution for static data and dynamic data still needs
16
+ treatment during layout rendering. This plugin aims to help with a set of
17
+ [filters](https://www.11ty.dev/docs/filters/) and
18
+ [shortcodes](https://www.11ty.dev/docs/shortcodes/).
8
19
 
9
- 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_.
20
+ The implementations of the filters are mostly wrappers around the
21
+ [ECMAScript Internationalization API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl)
22
+ with a little _bit of sugar_.
10
23
 
11
24
  ## Usage
12
- This guide corresponds to [Eleventy documentation](https://www.11ty.dev/docs/plugins/#add-the-plugin-to-eleventy-in-your-config-file):
25
+
26
+ This guide corresponds to
27
+ [Eleventy documentation](https://www.11ty.dev/docs/plugins/#add-the-plugin-to-eleventy-in-your-config-file):
13
28
 
14
29
  1. Install the package
15
- ```bash
16
- npm install --save @pcdevil/eleventy-plugin-intl-utils
17
- ```
30
+ ```bash
31
+ npm install --save @pcdevil/eleventy-plugin-intl-utils
32
+ ```
18
33
 
19
34
  2. Add to your config file
20
- ```javascript
21
- // file: .eleventy.js
22
- const intlUtils = require('@pcdevil/eleventy-plugin-intl-utils');
35
+ ```javascript
36
+ // file: eleventy.config.js
37
+ import intlUtils from '@pcdevil/eleventy-plugin-intl-utils';
23
38
 
24
- module.exports = function (eleventyConfig) {
25
- // ...
39
+ export default async function (eleventyConfig) {
40
+ // ...
26
41
 
27
- const intlUtilConfig = {
28
- locale: 'en-GB',
29
- };
30
- eleventyConfig.addPlugin(intlUtils, intlUtilConfig);
31
- };
32
- ```
42
+ eleventyConfig.addPlugin(intlUtils, {
43
+ locale: 'en-GB',
44
+ });
45
+ }
46
+ ```
33
47
 
34
48
  ## Configuration object
35
- A general configuration object can be passed optionally via Eleventy config when the plugin is initiated. This sections lists the available configuration properties.
49
+
50
+ A general configuration object can be passed optionally via Eleventy config when
51
+ the plugin is initiated. This sections lists the available configuration
52
+ properties.
36
53
 
37
54
  ### `locale`
38
- 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.
55
+
56
+ This property affects the output language of the filters. See
57
+ [`locales` argument section on Intl page](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument)
58
+ for more info.
39
59
 
40
60
  - **Type**: String
41
- - **Default value**: `undefined` (**Node.js** will pick up the system's language)
61
+ - **Default value**: `undefined` (**Node.js** will pick up the system's
62
+ language)
42
63
  - **Example values**: `"en-GB"`, `"hu"`
43
64
 
44
65
  ## Filters
45
66
 
46
67
  ### `country_name`
47
- Transforms a country code into a country name. Useful to display author's location.
48
68
 
49
- - **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))
69
+ Transforms a country code into a country name. Useful to display author's
70
+ location.
71
+
72
+ - **Used Internationalization API**: `Intl.DisplayNames()` with _region_ type
73
+ ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames))
50
74
 
51
75
  #### LiquidJS Example
52
76
 
@@ -58,9 +82,12 @@ Transforms a country code into a country name. Useful to display author's locati
58
82
  This renders "France" when the `intlUtilConfig.locale` is `en`.
59
83
 
60
84
  ### `language_name`
61
- Transforms a language code to a renderable text. Useful for language selectors or when the current language is displayed.
62
85
 
63
- - **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))
86
+ Transforms a language code to a renderable text. Useful for language selectors
87
+ or when the current language is displayed.
88
+
89
+ - **Used Internationalization API**: `Intl.DisplayNames()` with _language_ type
90
+ ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/DisplayNames#using_type_language_with_languagedisplay))
64
91
 
65
92
  #### LiquidJS Example
66
93
 
@@ -72,9 +99,12 @@ Transforms a language code to a renderable text. Useful for language selectors o
72
99
  This renders "British English" when the `intlUtilConfig.locale` is `en`.
73
100
 
74
101
  ### `short_datetime_format`
102
+
75
103
  Transforms a date string to a short date time text. Useful for blog post dates.
76
104
 
77
- - **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))
105
+ - **Used Internationalization API**: `Intl.DateTimeFormat()` with _short_ date
106
+ and time style
107
+ ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat))
78
108
 
79
109
  #### LiquidJS Example
80
110
 
@@ -88,11 +118,16 @@ This renders "12/12/21, 5:36 PM" when the `intlUtilConfig.locale` is `en`.
88
118
  ## Shortcodes
89
119
 
90
120
  ### `year_interval`
91
- Transforms two date strings to a year range. Useful when a larger time interval is presented.
92
121
 
93
- The input should be an array with two date string and the first one should precede before the second one.
122
+ Transforms two date strings to a year range. Useful when a larger time interval
123
+ is presented.
94
124
 
95
- - **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))
125
+ The input should be an array with two date string and the first one should
126
+ precede before the second one.
127
+
128
+ - **Used Internationalization API**:
129
+ `Intl.DateTimeFormat.prototype.formatRange()` with _numeric_ year
130
+ ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange))
96
131
 
97
132
  #### LiquidJS Example
98
133
 
@@ -102,10 +137,13 @@ The input should be an array with two date string and the first one should prece
102
137
  {% year_interval startDate, endDate %}
103
138
  ```
104
139
 
105
- This renders "2011 – 2020" (with en dash in the middle) when the `intlUtilConfig.locale` is `en`.
140
+ This renders "2011 – 2020" (with en dash in the middle) when the
141
+ `intlUtilConfig.locale` is `en`.
106
142
 
107
143
  #### Fallback value
108
- The second `endDate` argument can be omitted and it has the current date as default value.
144
+
145
+ The second `endDate` argument can be omitted and it has the current date as
146
+ default value.
109
147
 
110
148
  This behaviour helps when an open-ended / ongoing interval needs be displayed:
111
149
 
@@ -114,12 +152,17 @@ This behaviour helps when an open-ended / ongoing interval needs be displayed:
114
152
  {% year_interval startDate %}
115
153
  ```
116
154
 
117
- This renders "2011 – 2021" (with en dash in the middle) when the `intlUtilConfig.locale` is `en` and the current year is 2021.
155
+ This renders "2011 – 2021" (with en dash in the middle) when the
156
+ `intlUtilConfig.locale` is `en` and the current year is 2021.
118
157
 
119
158
  ### `year_open_interval`
120
- Transforms a date string into an _open_ year range where the end date is absent. Useful when a ongoing interval is presented.
121
159
 
122
- - **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))
160
+ Transforms a date string into an _open_ year range where the end date is absent.
161
+ Useful when a ongoing interval is presented.
162
+
163
+ - **Used Internationalization API**:
164
+ `Intl.DateTimeFormat.prototype.formatRange()` with _numeric_ year
165
+ ([MDN article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatRange))
123
166
 
124
167
  #### LiquidJS Example
125
168
 
@@ -128,10 +171,26 @@ Transforms a date string into an _open_ year range where the end date is absent.
128
171
  {% year_interval startDate %}
129
172
  ```
130
173
 
131
- This renders "2011 – " (with en dash in the middle) when the `intlUtilConfig.locale` is `en`.
174
+ This renders "2011 – " (with en dash in the middle) when the
175
+ `intlUtilConfig.locale` is `en`.
132
176
 
133
177
  #### Difference from `year_interval`
134
- 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
178
 
136
- ## License
137
- Available under the [MIT license](LICENSE.md).
179
+ While the [`year_interval`](#year_interval) shortcode always created a _closed_
180
+ year range (by applying the current year as default), the `year_open_interval`
181
+ only displays the start date.
182
+
183
+ ## License and acknowledgments
184
+
185
+ The project is available under the **3-Clause BSD** license with an extension of
186
+ prohibiting to use it with Gen-AI and LLMs tools, see the
187
+ [LICENSE.md](LICENSE.md) file.
188
+
189
+ "Human made content badge" badge created by **Andy Carolan**:
190
+ <https://www.andycarolan.com/>
191
+
192
+ License based on **Aleksandar Prokopec**'s Non-AI Licenses:
193
+ <https://github.com/non-ai-licenses/non-ai-licenses>
194
+
195
+ `AGENTS.md` is created by **Alice D.**:
196
+ <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": "1.1.0",
3
+ "version": "2.0.1",
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": ">= 18.0.0"
10
+ "node": "^26.12.1",
11
+ "npm": "^11.20.0"
11
12
  },
12
- "main": "./src/eleventy.js",
13
+ "packageManager": "npm@11.20.0",
14
+ "main": "./src/eleventy-plugin-intl-utils.mjs",
15
+ "type": "module",
16
+ "files": [
17
+ "src"
18
+ ],
13
19
  "scripts": {
14
- "format": "prettier --check src/",
15
- "format:fix": "npm run format -- --write",
16
- "lint": "npx eslint --ignore-path .gitignore .",
17
- "lint:fix": "npm run lint -- --fix",
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": "git+https://github.com/pcdevil/eleventy-plugin-intl-utils.git"
31
+ "url": "https://codeberg.org/pcdevil/eleventy-plugin-intl-utils.git"
25
32
  },
26
33
  "keywords": [
27
34
  "11ty",
@@ -36,13 +43,19 @@
36
43
  "name": "Attila Gonda",
37
44
  "url": "https://attilagonda.com"
38
45
  },
39
- "license": "MIT",
46
+ "license": "BSD-3-Clause-NO-AI",
40
47
  "bugs": {
41
- "url": "https://github.com/pcdevil/eleventy-plugin-intl-utils/issues"
48
+ "url": "https://codeberg.org/pcdevil/eleventy-plugin-intl-utils/issues"
42
49
  },
43
- "homepage": "https://github.com/pcdevil/eleventy-plugin-intl-utils#readme",
50
+ "homepage": "https://codeberg.org/pcdevil/eleventy-plugin-intl-utils",
44
51
  "devDependencies": {
45
- "eslint": "^8.36.0",
46
- "prettier": "^2.8.6"
52
+ "@eslint/config-helpers": "~0.7.0",
53
+ "@eslint/js": "^10.0.1",
54
+ "dprint": "~0.64.1",
55
+ "eslint": "^10.13.0",
56
+ "globals": "^17.13.0"
57
+ },
58
+ "allowScripts": {
59
+ "dprint@*": true
47
60
  }
48
61
  }
@@ -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
- 'use strict';
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
- 'use strict';
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
- 'use strict';
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
- 'use strict';
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
- 'use strict';
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
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/prettierrc",
3
- "printWidth": 300,
4
- "proseWrap": "never",
5
- "semi": true,
6
- "singleAttributePerLine": true,
7
- "singleQuote": true,
8
- "tabWidth": 2,
9
- "trailingComma": "all",
10
- "useTabs": true
11
- }
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
- };