Skip to content

Commit

Permalink
Fix sr pluralization
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Dec 31, 2022
1 parent 13ee177 commit 65b4926
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/Carbon/AbstractTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct($locale, MessageFormatterInterface $formatter = null
$this->initializing = true;
$this->directories = [__DIR__.'/Lang'];
$this->addLoader('array', new ArrayLoader());
parent::__construct($locale, $formatter, $cacheDir, $debug);
parent::__construct($locale, new MessageFormatterMapper($formatter), $cacheDir, $debug);
$this->initializing = false;
}

Expand Down
22 changes: 11 additions & 11 deletions src/Carbon/Lang/sr_Cyrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@
use Carbon\CarbonInterface;

return [
'year' => '{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count године|[0,Inf[:count година',
'year' => ':count година|:count године|:count година',
'y' => ':count г.',
'month' => '{1}:count месец|{2,3,4}:count месеца|[0,Inf[:count месеци',
'month' => ':count месец|:count месеца|:count месеци',
'm' => ':count м.',
'week' => '{1}:count недеља|{2,3,4}:count недеље|[0,Inf[:count недеља',
'week' => ':count недеља|:count недеље|:count недеља',
'w' => ':count нед.',
'day' => '{1,21,31}:count дан|[0,Inf[:count дана',
'day' => ':count дан|:count дана|:count дана',
'd' => ':count д.',
'hour' => '{1,21}:count сат|{2,3,4,22,23,24}:count сата|[0,Inf[:count сати',
'hour' => ':count сат|:count сата|:count сати',
'h' => ':count ч.',
'minute' => '{1,21,31,41,51}:count минут|[0,Inf[:count минута',
'minute' => ':count минут|:count минута|:count минута',
'min' => ':count мин.',
'second' => '{1,21,31,41,51}:count секунд|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count секунде|[0,Inf[:count секунди',
'second' => ':count секунд|:count секунде|:count секунди',
's' => ':count сек.',
'ago' => 'пре :time',
'from_now' => 'за :time',
'after' => ':time након',
'before' => ':time пре',
'year_from_now' => '{1,21,31,41,51}:count годину|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count године|[0,Inf[:count година',
'year_ago' => '{1,21,31,41,51}:count годину|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count године|[0,Inf[:count година',
'week_from_now' => '{1}:count недељу|{2,3,4}:count недеље|[0,Inf[:count недеља',
'week_ago' => '{1}:count недељу|{2,3,4}:count недеље|[0,Inf[:count недеља',
'year_from_now' => ':count годину|:count године|:count година',
'year_ago' => ':count годину|:count године|:count година',
'week_from_now' => ':count недељу|:count недеље|:count недеља',
'week_ago' => ':count недељу|:count недеље|:count недеља',
'diff_now' => 'управо сада',
'diff_today' => 'данас',
'diff_today_regexp' => 'данас(?:\\s+у)?',
Expand Down
22 changes: 11 additions & 11 deletions src/Carbon/Lang/sr_Cyrl_ME.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@
use Carbon\CarbonInterface;

return [
'year' => '{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count године|[0,Inf[:count година',
'year' => ':count година|:count године|:count година',
'y' => ':count г.',
'month' => '{1}:count мјесец|{2,3,4}:count мјесеца|[0,Inf[:count мјесеци',
'month' => ':count мјесец|:count мјесеца|:count мјесеци',
'm' => ':count мј.',
'week' => '{1}:count недјеља|{2,3,4}:count недјеље|[0,Inf[:count недјеља',
'week' => ':count недјеља|:count недјеље|:count недјеља',
'w' => ':count нед.',
'day' => '{1,21,31}:count дан|[0,Inf[:count дана',
'day' => ':count дан|:count дана|:count дана',
'd' => ':count д.',
'hour' => '{1,21}:count сат|{2,3,4,22,23,24}:count сата|[0,Inf[:count сати',
'hour' => ':count сат|:count сата|:count сати',
'h' => ':count ч.',
'minute' => '{1,21,31,41,51}:count минут|[0,Inf[:count минута',
'minute' => ':count минут|:count минута|:count минута',
'min' => ':count мин.',
'second' => '{1,21,31,41,51}:count секунд|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count секунде|[0,Inf[:count секунди',
'second' => ':count секунд|:count секунде|:count секунди',
's' => ':count сек.',
'ago' => 'прије :time',
'from_now' => 'за :time',
'after' => ':time након',
'before' => ':time прије',

'year_from_now' => '{1,21,31,41,51}:count годину|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count године|[0,Inf[:count година',
'year_ago' => '{1,21,31,41,51}:count годину|{2,3,4,22,23,24,32,33,34,42,43,44,52,53,54}:count године|[0,Inf[:count година',
'year_from_now' => ':count годину|:count године|:count година',
'year_ago' => ':count годину|:count године|:count година',

'week_from_now' => '{1}:count недјељу|{2,3,4}:count недјеље|[0,Inf[:count недјеља',
'week_ago' => '{1}:count недјељу|{2,3,4}:count недјеље|[0,Inf[:count недјеља',
'week_from_now' => ':count недјељу|:count недјеље|:count недјеља',
'week_ago' => ':count недјељу|:count недјеље|:count недјеља',

'diff_now' => 'управо сада',
'diff_today' => 'данас',
Expand Down
1 change: 1 addition & 0 deletions src/Carbon/Lang/sr_Latn_ME.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'before' => ':time prije',
'week_from_now' => ':count nedjelju|:count nedjelje|:count nedjelja',
'week_ago' => ':count nedjelju|:count nedjelje|:count nedjelja',
'second_ago' => ':count sekund|:count sekunde|:count sekundi',
'diff_tomorrow' => 'sjutra',
'calendar' => [
'nextDay' => '[sjutra u] LT',
Expand Down
34 changes: 34 additions & 0 deletions src/Carbon/MessageFormatterMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* This file is part of the Carbon package.
*
* (c) Brian Nesbitt <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Carbon;

use Symfony\Component\Translation\Formatter\MessageFormatter;
use Symfony\Component\Translation\Formatter\MessageFormatterInterface;

final class MessageFormatterMapper implements MessageFormatterInterface
{
/** @var MessageFormatterInterface */
private $formatter;
public function __construct(?MessageFormatterInterface $formatter = null)
{
$this->formatter = $formatter ?? new MessageFormatter();
}

public function format(string $message, string $locale, array $parameters = []): string
{
return $this->formatter->format(
$message,
preg_replace('/[_@][A-Za-z][a-z]{2,}/', '', $locale),
$parameters
);
}
}
30 changes: 15 additions & 15 deletions tests/Localization/SrLatnBaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->subSeconds(2)->diffForHumans()
// '2 seconds ago'
'pre 2 sekundu',
'pre 2 sekunde',

// Carbon::now()->subSeconds(2)->diffForHumans(null, false, true)
// '2s ago'
Expand All @@ -251,7 +251,7 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->subMinutes(2)->diffForHumans()
// '2 minutes ago'
'pre 2 minut',
'pre 2 minuta',

// Carbon::now()->subMinutes(2)->diffForHumans(null, false, true)
// '2m ago'
Expand All @@ -267,7 +267,7 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->subHours(2)->diffForHumans()
// '2 hours ago'
'pre 2 sat',
'pre 2 sata',

// Carbon::now()->subHours(2)->diffForHumans(null, false, true)
// '2h ago'
Expand All @@ -283,7 +283,7 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->subDays(2)->diffForHumans()
// '2 days ago'
'pre 2 dan',
'pre 2 dana',

// Carbon::now()->subDays(2)->diffForHumans(null, false, true)
// '2d ago'
Expand All @@ -299,7 +299,7 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->subWeeks(2)->diffForHumans()
// '2 weeks ago'
'pre 2 nedelju',
'pre 2 nedelje',

// Carbon::now()->subWeeks(2)->diffForHumans(null, false, true)
// '2w ago'
Expand All @@ -315,7 +315,7 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->subMonths(2)->diffForHumans()
// '2 months ago'
'pre 2 mesec',
'pre 2 meseca',

// Carbon::now()->subMonths(2)->diffForHumans(null, false, true)
// '2mos ago'
Expand All @@ -331,7 +331,7 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->subYears(2)->diffForHumans()
// '2 years ago'
'pre 2 godinu',
'pre 2 godine',

// Carbon::now()->subYears(2)->diffForHumans(null, false, true)
// '2yrs ago'
Expand Down Expand Up @@ -371,7 +371,7 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->diffForHumans(Carbon::now()->addSecond()->addSecond(), true)
// '2 seconds'
'2 sekundu',
'2 sekunde',

// Carbon::now()->diffForHumans(Carbon::now()->addSecond()->addSecond(), true, true)
// '2s'
Expand All @@ -391,7 +391,7 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->addYears(3)->diffForHumans(null, null, false, 4)
// '3 years from now'
'za 3 godinu',
'za 3 godine',

// Carbon::now()->subMonths(5)->diffForHumans(null, null, true, 4)
// '5mos ago'
Expand All @@ -403,31 +403,31 @@ class SrLatnBaTest extends LocalizationTestCase

// Carbon::now()->addWeek()->addHours(10)->diffForHumans(null, true, false, 2)
// '1 week 10 hours'
'1 nedelja 10 sat',
'1 nedelja 10 sati',

// Carbon::now()->addWeek()->addDays(6)->diffForHumans(null, true, false, 2)
// '1 week 6 days'
'1 nedelja 6 dan',
'1 nedelja 6 dana',

// Carbon::now()->addWeek()->addDays(6)->diffForHumans(null, true, false, 2)
// '1 week 6 days'
'1 nedelja 6 dan',
'1 nedelja 6 dana',

// Carbon::now()->addWeek()->addDays(6)->diffForHumans(["join" => true, "parts" => 2])
// '1 week and 6 days from now'
'za 1 nedelju i 6 dan',
'za 1 nedelju i 6 dana',

// Carbon::now()->addWeeks(2)->addHour()->diffForHumans(null, true, false, 2)
// '2 weeks 1 hour'
'2 nedelja 1 sat',
'2 nedelje 1 sat',

// Carbon::now()->addHour()->diffForHumans(["aUnit" => true])
// 'an hour from now'
'za 1 sat',

// CarbonInterval::days(2)->forHumans()
// '2 days'
'2 dan',
'2 dana',

// CarbonInterval::create('P1DT3H')->forHumans(true)
// '1d 3h'
Expand Down
8 changes: 4 additions & 4 deletions tests/Localization/SrLatnMeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,19 @@ class SrLatnMeTest extends LocalizationTestCase

// Carbon::now()->addWeek()->addDays(6)->diffForHumans(null, true, false, 2)
// '1 week 6 days'
'1 nedjelja 6 dan',
'1 nedjelja 6 dana',

// Carbon::now()->addWeek()->addDays(6)->diffForHumans(null, true, false, 2)
// '1 week 6 days'
'1 nedjelja 6 dan',
'1 nedjelja 6 dana',

// Carbon::now()->addWeek()->addDays(6)->diffForHumans(["join" => true, "parts" => 2])
// '1 week and 6 days from now'
'za 1 nedjelju i 6 dan',
'za 1 nedjelju i 6 dana',

// Carbon::now()->addWeeks(2)->addHour()->diffForHumans(null, true, false, 2)
// '2 weeks 1 hour'
'2 nedjelja 1 sat',
'2 nedjelje 1 sat',

// Carbon::now()->addHour()->diffForHumans(["aUnit" => true])
// 'an hour from now'
Expand Down
30 changes: 15 additions & 15 deletions tests/Localization/SrLatnXkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->subSeconds(2)->diffForHumans()
// '2 seconds ago'
'pre 2 sekundu',
'pre 2 sekunde',

// Carbon::now()->subSeconds(2)->diffForHumans(null, false, true)
// '2s ago'
Expand All @@ -251,7 +251,7 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->subMinutes(2)->diffForHumans()
// '2 minutes ago'
'pre 2 minut',
'pre 2 minuta',

// Carbon::now()->subMinutes(2)->diffForHumans(null, false, true)
// '2m ago'
Expand All @@ -267,7 +267,7 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->subHours(2)->diffForHumans()
// '2 hours ago'
'pre 2 sat',
'pre 2 sata',

// Carbon::now()->subHours(2)->diffForHumans(null, false, true)
// '2h ago'
Expand All @@ -283,7 +283,7 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->subDays(2)->diffForHumans()
// '2 days ago'
'pre 2 dan',
'pre 2 dana',

// Carbon::now()->subDays(2)->diffForHumans(null, false, true)
// '2d ago'
Expand All @@ -299,7 +299,7 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->subWeeks(2)->diffForHumans()
// '2 weeks ago'
'pre 2 nedelju',
'pre 2 nedelje',

// Carbon::now()->subWeeks(2)->diffForHumans(null, false, true)
// '2w ago'
Expand All @@ -315,7 +315,7 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->subMonths(2)->diffForHumans()
// '2 months ago'
'pre 2 mesec',
'pre 2 meseca',

// Carbon::now()->subMonths(2)->diffForHumans(null, false, true)
// '2mos ago'
Expand All @@ -331,7 +331,7 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->subYears(2)->diffForHumans()
// '2 years ago'
'pre 2 godinu',
'pre 2 godine',

// Carbon::now()->subYears(2)->diffForHumans(null, false, true)
// '2yrs ago'
Expand Down Expand Up @@ -371,7 +371,7 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->diffForHumans(Carbon::now()->addSecond()->addSecond(), true)
// '2 seconds'
'2 sekundu',
'2 sekunde',

// Carbon::now()->diffForHumans(Carbon::now()->addSecond()->addSecond(), true, true)
// '2s'
Expand All @@ -391,7 +391,7 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->addYears(3)->diffForHumans(null, null, false, 4)
// '3 years from now'
'za 3 godinu',
'za 3 godine',

// Carbon::now()->subMonths(5)->diffForHumans(null, null, true, 4)
// '5mos ago'
Expand All @@ -403,31 +403,31 @@ class SrLatnXkTest extends LocalizationTestCase

// Carbon::now()->addWeek()->addHours(10)->diffForHumans(null, true, false, 2)
// '1 week 10 hours'
'1 nedelja 10 sat',
'1 nedelja 10 sati',

// Carbon::now()->addWeek()->addDays(6)->diffForHumans(null, true, false, 2)
// '1 week 6 days'
'1 nedelja 6 dan',
'1 nedelja 6 dana',

// Carbon::now()->addWeek()->addDays(6)->diffForHumans(null, true, false, 2)
// '1 week 6 days'
'1 nedelja 6 dan',
'1 nedelja 6 dana',

// Carbon::now()->addWeek()->addDays(6)->diffForHumans(["join" => true, "parts" => 2])
// '1 week and 6 days from now'
'za 1 nedelju i 6 dan',
'za 1 nedelju i 6 dana',

// Carbon::now()->addWeeks(2)->addHour()->diffForHumans(null, true, false, 2)
// '2 weeks 1 hour'
'2 nedelja 1 sat',
'2 nedelje 1 sat',

// Carbon::now()->addHour()->diffForHumans(["aUnit" => true])
// 'an hour from now'
'za 1 sat',

// CarbonInterval::days(2)->forHumans()
// '2 days'
'2 dan',
'2 dana',

// CarbonInterval::create('P1DT3H')->forHumans(true)
// '1d 3h'
Expand Down

0 comments on commit 65b4926

Please sign in to comment.