@pcdevil/eleventy-plugin-intl-utils 0.2.0 → 0.3.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/.eleventy.js +6 -5
- package/README.md +24 -3
- package/package.json +1 -1
- package/src/{country_name.js → filters/country_name.js} +0 -0
- package/src/{language_name.js → filters/language_name.js} +0 -0
- package/src/{short_datetime_format.js → filters/short_datetime_format.js} +0 -0
- package/src/{year_interval.js → shortcodes/year_interval.js} +1 -1
package/.eleventy.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const countryNameFactory = require('./src/country_name');
|
|
4
|
-
const languageNameFactory = require('./src/language_name');
|
|
5
|
-
const shortDateTimeFormatFactory = require('./src/short_datetime_format');
|
|
6
|
-
const yearIntervalFactory = require('./src/year_interval');
|
|
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
7
|
|
|
8
8
|
module.exports = (eleventyConfig, pluginConfig = {}) => {
|
|
9
9
|
const { locale } = pluginConfig;
|
|
@@ -11,5 +11,6 @@ module.exports = (eleventyConfig, pluginConfig = {}) => {
|
|
|
11
11
|
eleventyConfig.addFilter('country_name', countryNameFactory(locale));
|
|
12
12
|
eleventyConfig.addFilter('language_name', languageNameFactory(locale));
|
|
13
13
|
eleventyConfig.addFilter('short_datetime_format', shortDateTimeFormatFactory(locale));
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
eleventyConfig.addShortcode('year_interval', yearIntervalFactory(locale));
|
|
15
16
|
};
|
package/README.md
CHANGED
|
@@ -4,10 +4,17 @@ A set of internationalization utils for [Eleventy](https://www.11ty.dev/).
|
|
|
4
4
|
## Motivation
|
|
5
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
6
|
|
|
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/).
|
|
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/).
|
|
8
8
|
|
|
9
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_.
|
|
10
10
|
|
|
11
|
+
## Current state
|
|
12
|
+
The package uses [Semantic Versioning](https://semver.org/) to signal changes between releases.
|
|
13
|
+
|
|
14
|
+
Currently is at _major version zero_ and as [the specification states](https://semver.org/#spec-item-4) the current API is not at stable state.
|
|
15
|
+
|
|
16
|
+
Please always compare versions between updates!
|
|
17
|
+
|
|
11
18
|
## Usage
|
|
12
19
|
This guide corresponds to [Eleventy documentation](https://www.11ty.dev/docs/plugins/#add-the-plugin-to-eleventy-in-your-config-file):
|
|
13
20
|
|
|
@@ -82,6 +89,8 @@ Transforms a date string to a short date time text. Useful for blog post dates.
|
|
|
82
89
|
{% comment %} renders "12/12/21, 5:36 PM" when the `intlUtilConfig.locale` is `en` {% endcomment %}
|
|
83
90
|
```
|
|
84
91
|
|
|
92
|
+
## Shortcodes
|
|
93
|
+
|
|
85
94
|
### `year_interval`
|
|
86
95
|
Transforms two date strings to a year range. Useful when a larger time interval is presented.
|
|
87
96
|
|
|
@@ -92,10 +101,22 @@ The input should be an array with two date string and the first one should prece
|
|
|
92
101
|
#### LiquidJS Example
|
|
93
102
|
|
|
94
103
|
```
|
|
95
|
-
{% assign
|
|
96
|
-
{
|
|
104
|
+
{% assign startDate = "2011-05-16 11:00 +0200" %}
|
|
105
|
+
{% assign endDate = "2020-03-01 00:00 +0100" %}
|
|
106
|
+
{% year_interval startDate, endDate %}
|
|
97
107
|
{% comment %} renders "2011 – 2020" (with en dash in the middle) when the `intlUtilConfig.locale` is `en` {% endcomment %}
|
|
98
108
|
```
|
|
99
109
|
|
|
110
|
+
#### Fallback value
|
|
111
|
+
The second `endDate` argument can be omitted and it has the current date as default value.
|
|
112
|
+
|
|
113
|
+
This behaviour helps when an open-ended / ongoing interval needs be displayed:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
{% assign startDate = "2011-05-16 11:00 +0200" %}
|
|
117
|
+
{% year_interval startDate %}
|
|
118
|
+
{% comment %} renders "2011 – 2021" (with en dash in the middle) when the `intlUtilConfig.locale` is `en` and the current year is 2021 {% endcomment %}
|
|
119
|
+
```
|
|
120
|
+
|
|
100
121
|
## License
|
|
101
122
|
Available under the [MIT license](LICENSE.md).
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -5,7 +5,7 @@ function yearIntervalFactory (locale) {
|
|
|
5
5
|
year: 'numeric',
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
return (
|
|
8
|
+
return (startDate, endDate = new Date()) => dateTimeFormat.formatRange(new Date(startDate), new Date(endDate));
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
module.exports = yearIntervalFactory;
|