Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/texnixe/kirby-relativedate
Relative Date and Time (multi-language) plugin for Kirby 2 CMS
https://github.com/texnixe/kirby-relativedate
Last synced: about 2 months ago
JSON representation
Relative Date and Time (multi-language) plugin for Kirby 2 CMS
- Host: GitHub
- URL: https://github.com/texnixe/kirby-relativedate
- Owner: texnixe
- Created: 2015-03-06T15:05:58.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-05T02:02:59.000Z (almost 10 years ago)
- Last Synced: 2023-08-07T04:38:32.517Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 110 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kirby 2 - Relative Date Plugin v0.9
Plugin for Kirby 2 CMS that coverts date and time to a human-readable relative format: Converts your absolute date (and time) in something relative and more readable, e.g.:
```
2 months 3 days ago
5 hours 47 minutes 18 seconds from now
```# Installation & Usage
1. [Download](https://github.com/distantnative/kirby-relativedate/archive/develop.zip) the current release.
2. Add the ```relative-date.php``` and ```lang``` folder to the ```site/plugins/relative-date/``` directory. You probably need to create the ```relative-date```folder.
3. Then use it on any date field, e.g.:
```php
$page->published()->relative()
```To **update** to a higher version just replace the same files by their newer version.
# Options
### Threshold
Sometimes you only want relative dates for dates that are not too far in the past/future, but not for dates really far away. In that case you can set a threshold (in seconds). Only dates on the range of that threshold from the current time will be displayed as relative dates.Globally in your ```sites/config/config.php```:
```php
c::set('relativedate.threshold', 604800);
```On a per case basis:
```php
$page->published()->relative(604800);
```### Length
You can define how many date/time elements the phrase should entail. The default is 2 elements (e.g. '1 year 4 months' or '2 weeks 3 days' or '2 hours 34 minutes'). You can set your own phrase length in two ways:Globally in your ```sites/config/config.php```:
```php
c::set('relativedate.length', 4);
```On a per case basis:
```php
$page->published()->relative($threshold, 4);
```### Default Language
You can also define the default fallback language (if not, it's English) in your ```sites/config/config.php```:```php
c::set('relativedate.default', 'ja');
```# Fuzzy expressions
There is a way to get more fuzzy expressions, e.g. ```yesterday```instead of ```17 hours 40 minutes ago```. For that you need to set up the fuzzy expressions, which you want to use, in your ```site/config/config.php```, e.g.:```php
c::set('relativedate.fuzzy', array(
/* English (en) */
'en' => array(
'tomorrow' => '/^[1-2]?[1-9] hour(s)?(.*)/',
'yesterday' => '/^(1 day(.*)|[1-2]?[1-9] hour(s)?(.*))/',
),
));
```
The config item consists of an array in which each language gets its own array of fuzzy expressions. Each fuzzy expression consists of a key-value pair. They key represents the fuzzy term that you wanna have in your displayed result at the end, the value containts a regular expression of what is to replace.You can find a collection of fuzzy expression rules for different languages in the ```fuzzy-examples.php```file.
# Help & Improve
Help is always appreciated. Suggestions, ideas or bugs - let me please know by [opening an issue](https://github.com/distantnative/kirby-relativedate/issues).In addition, if you think a language is missing, [let me know](https://github.com/distantnative/kirby-relativedate/issues/11). And if you can even help with the translation, please provide the following information:
- Words (singular & plural) for second, minute, hour, day, week, month and year
- Terms that express A) that date & time are in the future (e.g. "1 hour from now") and B) that date & time are in the past (e.g. "3 days ago")
- Where to put these terms in relation to the date/time-phrase (before, after, in between?)# Languages supported
- English (en) *[default]*
- Arabic (ar) *[experimental]*
- Bulgarian (bg)
- Chinese (zh)
- Chinese Taiwan (zh_TW)
- Czech (cs)
- Danish (da)
- Dutch (nl)
- Finnish (fi)
- French (fr)
- German (de)
- Italian (it)
- Japanese (ja)
- Norwegian (no)
- Polish (pol)
- Portuguese (pt)
- Portuguese Brazilian (pt_BR)
- Russian (ru)
- Serbian (sr)
- Spanish (es)
- Swedish (sv)
- Thai (th)
- Turkish (tr)Credits go to the [Laravel Date project](https://github.com/jenssegers/laravel-date/tree/master/src/lang) for their languages variables as well as [this localization guide](http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html) for providing the plural set rules.
# Version history
**v0.9**
- Added [threshold option](#threshold)
- Complete rewrite [fuzzy expression](#fuzzy) logic, located it to ```site/config/config.php```
- Added Czech, Bulgarian, Chinese, Chinese Taiwan, Danish support
- Improved minor things on Thai translation**v0.8**
- Complete rewrite of logic for languages that feature multiple plural forms with specific rule sets (e.g. Russian)
- Fixed Russian localization
- Added support for Norwegian, Polish, Brazilian Portuguese, Finnish, Turkish, Serbian
- Added experimental support for Arabic**v0.7**
- Added basic [fuzzy expression support](#fuzzy)
- Fixed wrong language matching for years
- Code simplifications