Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Added support of months in genitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Amegatron committed Dec 21, 2014
1 parent 705b6e1 commit 10e7a30
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
/vendor
composer.phar
composer.lock
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ See also [localized documentation](docs)
<a name="intro"></a>
## Introduction

Localized Carbon is an extension of a popular Carbon package, designed specially for Laravel framework. By localization I mean its `diffForHumans` function, which returns a human-readable string of time interval.
Localized Carbon is an extension of a popular Carbon package, designed specially for Laravel framework. By localization I mean its `diffForHumans` function, which returns a human-readable string of time interval. This package also supports genitive months by introducing the "%f" key in `formatLocalized` method.

<a name="usage"></a>
## Usage
Expand Down Expand Up @@ -42,16 +42,16 @@ Also `LocalizedCarbon` adds an optional second argument, in which you may specif

Current version of Localized Carbon ships with these localizations:

+ English (en)
+ Russian (ru)
+ Ukrainian (uk)
+ Dutch (nl)
+ Spanish (es)
+ Portuguese (pt)
+ French (fr)
+ Bulgarian (bg)
+ Slovakian (sk)
+ Turkish (tr)
+ English (en) (full)
+ Russian (ru) (full)
+ Ukrainian (uk) (full)
+ Dutch (nl) (no genitive)
+ Spanish (es) (no genitive)
+ Portuguese (pt) (no genitive)
+ French (fr) (no genitive)
+ Bulgarian (bg) (no genitive)
+ Slovakian (sk) (no genitive)
+ Turkish (tr) (no genitive)

But it is extendable, so you may write and use your own localization without altering the contents of the package. See [extending Localized Carbon](#extending).

Expand Down Expand Up @@ -144,3 +144,5 @@ If you've written a formatter for the language which is not supported by current
The formatter should lie in `src/Laravelrus/LocalizedCarbon/DiffFormatters` directory, following a simple naming convention: the class name should start with the desired language in lower-case, but the first letter in upper-case. The rest part of the name should be "DiffFormatter". The file name should correspond to the class name.

For example, the formatter for `fr` language would lie in `src/Laravelrus/LocalizedCarbon/DiffFormatters/FrDiffFormatter.php`, and the class name would be `FrDiffFormatter`.

Also I need the help of the community to complete the list of genitives for all supported languages. If you know a language and it uses genitives in dates, feel free to contribute. See an example of Russian or Ukranian `lang\XX\months.php` files.
12 changes: 12 additions & 0 deletions src/Laravelrus/LocalizedCarbon/LocalizedCarbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,16 @@ public function diffForHumans(Carbon $other = null, $formatter = null) {

return $result;
}

public function formatLocalized($format = self::COOKIE) {
$result = parent::formatLocalized($format);

if (strpos($result, '%f') !== false) {
$langKey = strtolower(parent::format("F"));
$replace = \Lang::get("localized-carbon::months." . $langKey);
$result = str_replace('%f', $replace, $result);
}

return $result;
}
}
16 changes: 16 additions & 0 deletions src/lang/en/months.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return array(
"january" => "January",
"february" => "February",
"march" => "March",
"april" => "April",
"may" => "May",
"june" => "June",
"july" => "July",
"august" => "August",
"september" => "September",
"october" => "October",
"november" => "November",
"december" => "December",
);
16 changes: 16 additions & 0 deletions src/lang/ru/months.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return array(
"january" => "января",
"february" => "февраля",
"march" => "марта",
"april" => "апреля",
"may" => "мая",
"june" => "июня",
"july" => "июля",
"august" => "августа",
"september" => "сентября",
"october" => "октября",
"november" => "ноября",
"december" => "декабря",
);
16 changes: 16 additions & 0 deletions src/lang/uk/months.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return array(
"january" => "січня",
"february" => "лютого",
"march" => "березня",
"april" => "квітня",
"may" => "травня",
"june" => "червня",
"july" => "липня",
"august" => "серпня",
"september" => "вересня",
"october" => "жовтня",
"november" => "листопада",
"december" => "грудня",
);

0 comments on commit 10e7a30

Please sign in to comment.