@pcdevil/eleventy-plugin-intl-utils 1.0.2 → 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 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,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
- ```bash
16
- npm install --save @pcdevil/eleventy-plugin-intl-utils
17
- ```
20
+ ```bash
21
+ npm install --save @pcdevil/eleventy-plugin-intl-utils
22
+ ```
18
23
 
19
24
  2. Add to your config file
20
- ```javascript
21
- // file: .eleventy.js
22
- const intlUtils = require('@pcdevil/eleventy-plugin-intl-utils');
25
+ ```javascript
26
+ // file: eleventy.config.js
27
+ import intlUtils from '@pcdevil/eleventy-plugin-intl-utils';
23
28
 
24
- module.exports = function (eleventyConfig) {
25
- // ...
29
+ export default async function (eleventyConfig) {
30
+ // ...
26
31
 
27
- const intlUtilConfig = {
28
- locale: 'en-GB',
29
- };
30
- eleventyConfig.addPlugin(intlUtils, intlUtilConfig);
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:
@@ -116,5 +127,31 @@ This behaviour helps when an open-ended / ongoing interval needs be displayed:
116
127
 
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
- ## License
120
- Available under the [MIT license](LICENSE.md).
130
+ ### `year_open_interval`
131
+
132
+ Transforms a date string into an _open_ year range where the end date is absent. Useful when a ongoing interval is presented.
133
+
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))
135
+
136
+ #### LiquidJS Example
137
+
138
+ ```
139
+ {% assign startDate = "2011-05-16 11:00 +0200" %}
140
+ {% year_interval startDate %}
141
+ ```
142
+
143
+ This renders "2011 – " (with en dash in the middle) when the `intlUtilConfig.locale` is `en`.
144
+
145
+ #### Difference from `year_interval`
146
+
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.
148
+
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,21 +1,34 @@
1
1
  {
2
2
  "name": "@pcdevil/eleventy-plugin-intl-utils",
3
- "version": "1.0.2",
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": ">= 16.0.0"
10
+ "node": "^22.23.1",
11
+ "npm": "^10.9.8"
11
12
  },
12
- "main": ".eleventy.js",
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
- "lint": "npx eslint ."
20
+ "format": "dprint fmt",
21
+ "format:check-only": "dprint check",
22
+ "lint": "eslint --fix",
23
+ "lint:check-only": "eslint",
24
+ "release:major": "npm version major",
25
+ "release:minor": "npm version minor",
26
+ "release:patch": "npm version patch",
27
+ "update:dprint-plugins": "dprint config update"
15
28
  },
16
29
  "repository": {
17
30
  "type": "git",
18
- "url": "git+https://github.com/pcdevil/eleventy-plugin-intl-utils.git"
31
+ "url": "https://codeberg.org/pcdevil/eleventy-plugin-intl-utils.git"
19
32
  },
20
33
  "keywords": [
21
34
  "11ty",
@@ -30,16 +43,16 @@
30
43
  "name": "Attila Gonda",
31
44
  "url": "https://attilagonda.com"
32
45
  },
33
- "license": "MIT",
46
+ "license": "BSD-3-Clause-NO-AI",
34
47
  "bugs": {
35
- "url": "https://github.com/pcdevil/eleventy-plugin-intl-utils/issues"
48
+ "url": "https://codeberg.org/pcdevil/eleventy-plugin-intl-utils/issues"
36
49
  },
37
- "homepage": "https://github.com/pcdevil/eleventy-plugin-intl-utils#readme",
50
+ "homepage": "https://codeberg.org/pcdevil/eleventy-plugin-intl-utils",
38
51
  "devDependencies": {
39
- "eslint": "^8.14.0",
40
- "eslint-config-standard": "^17.0.0",
41
- "eslint-plugin-import": "^2.26.0",
42
- "eslint-plugin-n": "^15.2.0",
43
- "eslint-plugin-promise": "^6.0.0"
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"
44
57
  }
45
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
- '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;
@@ -0,0 +1,12 @@
1
+ export function yearOpenIntervalFactory (locale) {
2
+ const dateTimeFormat = new Intl.DateTimeFormat(locale, {
3
+ year: 'numeric',
4
+ });
5
+
6
+ return (startDate) =>
7
+ dateTimeFormat
8
+ .formatRangeToParts(new Date(startDate), new Date())
9
+ .filter(({ source }) => source !== 'endRange')
10
+ .map(({ value }) => value)
11
+ .join('');
12
+ }
package/.eleventy.js DELETED
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- const countryNameFactory = require('./src/filters/country_name');
4
- const languageNameFactory = require('./src/filters/language_name');
5
- const shortDateTimeFormatFactory = require('./src/filters/short_datetime_format');
6
- const yearIntervalFactory = require('./src/shortcodes/year_interval');
7
-
8
- module.exports = (eleventyConfig, pluginConfig = {}) => {
9
- const { locale } = pluginConfig;
10
-
11
- eleventyConfig.addFilter('country_name', countryNameFactory(locale));
12
- eleventyConfig.addFilter('language_name', languageNameFactory(locale));
13
- eleventyConfig.addFilter('short_datetime_format', shortDateTimeFormatFactory(locale));
14
-
15
- eleventyConfig.addShortcode('year_interval', yearIntervalFactory(locale));
16
- };