Comments (11)
Thats strange, I just tested it again, and just %f
works fine for me.
Route::get('/test', function() {
$date = \Laravelrus\LocalizedCarbon\LocalizedCarbon::create(2014, 6, 12);
return $date->formatLocalized('%f');
});
Output is июня
.
from localized-carbon.
@Amegatron probably, you are using windows. check the Carbon format method, there is a preg_replace function there for win users.
After this method, not on windows, I just get the f
letter, your example also shows the f
letter.
Latest version of 4.2 laravel, latest version of this package, mac os.
from localized-carbon.
I'm using homestead - so this is not under Windows. I checked the method used to determine Windows in original formatLocalized
:
strtoupper(substr(PHP_OS, 0, 3))
It returns LIN
.
I'm also having latest versions of Laravel and Carbon.
I suppose the issue occurs only under Mac. I'll think about better solution of it, but I need someone else to approve it on Mac.
from localized-carbon.
@Amegatron yes, that's strange
the native Carbon formatLocalized()
function returns
return strftime($format, $this->timestamp);
With %f
it returns just the f
letter. Idk why this differs.
I guess, that function works not the same on different php/os versions.
My php version is 5.5.10
from localized-carbon.
@Amegatron ok, I tested it. In fact, there is no %f
key in strftime
function.
I suggest using the standard %B
key for that.
I also tested the solution:
public function formatLocalized($format = self::COOKIE)
{
$result = parent::formatLocalized($format);
if (strpos($format, '%B') !== false)
{
$month = parent::format("F");
$localizedMonth = \Lang::get("localized-carbon::months." . strtolower($month));
$result = str_replace($month, $localizedMonth, $result);
}
return $result;
}
or even a shorter version
public function formatLocalized($format = self::COOKIE)
{
if (strpos($format, '%B') !== false)
{
$month = strtolower(parent::format("F"));
$localizedMonth = \Lang::get("localized-carbon::months." . $month);
$format = str_replace('%B', $localizedMonth, $format);
}
return parent::formatLocalized($format);
}
Also, consider changing lang files from январь
to Январь
- that is the default behavior, not the lowercase one.
Hope, this will help. Thanks for the package ;)
from localized-carbon.
That is the case, %f
is specially the key that is not used by default strftime
to not conflict with default behaviour. And also thats why I don't want to replace %B
because what if someone wants the default behaviour? I think that would not be a good solution.
Considering strftime
, I also now think that the reason is the difference between implementations of this function under different systems.
from localized-carbon.
@vladshcherbin Please check out my possible fix: e00eb79.
I first replace %f
and only then pass the string to parent::formatLocalized
.
from localized-carbon.
@Amegatron yes, that is definitely working.
you can shorten it by
public function formatLocalized($format = self::COOKIE)
{
if (strpos($format, '%f') !== false) {
$month = strtolower(parent::format("F"));
$localizedMonth = \Lang::get("localized-carbon::months." . $month);
$format = str_replace('%f', $localizedMonth, $format);
}
return parent::formatLocalized($format);
}
All in all, please consider changing to the %B
key & first letter uppercase, this is the expected behavior, there is no point in reinventing the wheel.
And if someone would want the default behaviour, the standard Carbon class should be used instead.
Thanks ;)
from localized-carbon.
I'll think about switching to %B
, but I'm not going to make first letter uppercase for Russian localization. First uppercase character is the standard in USA and England and maybe somewhere else, but not in Russia, we have lower-case characters, we do not write "16 Января 2014", but "16 января 2014". Even standart %B
behaviour uses lower-cased months.
Anyway, thanks for pointing out the issue about %%f
under Mac :)
from localized-carbon.
@vladshcherbin sorry, I meant %b
- abbreviated month, wich is in genitive for russian, e.g. "мая".
from localized-carbon.
@Amegatron yes, i checked the default %B
in russian, the result is lowercased.
So, if the %f
will be switched to the default %B
it would be super cool. Thanks.
from localized-carbon.
Related Issues (19)
- localized-carbon duplicate number of days in arabic language HOT 2
- Declaration of Laravelrus\LocalizedCarbon\LocalizedCarbon::diffForHumans(?Carbon\Carbon $other = NULL, $formatter = NULL) should be compatible with Carbon\Carbon::diffForHumans($other = NULL, $absolute = false, $short = false, $parts = 1) (View: resources/views/events/index.blade.php) HOT 1
- Laravel 5.3 support
- Make Eloquent plugin available as a trait HOT 1
- Laravel 5 HOT 10
- Add instruction on how to choose the language. HOT 1
- Short dates HOT 1
- Не работает HOT 2
- день недели HOT 1
- trait ломает работу seeds&faker HOT 1
- Call to undefined method [package] HOT 1
- Adding new file to Lang folder HOT 1
- Fails with latest Carbon version HOT 12
- Не работает diffForHumans HOT 2
- Как изменить локализацию на ru?
- Fails with laravel v5.6.11 and carbon v1.24.2 (latest version) HOT 1
- Declaration of LocalizedCarbon::diffForHumans() should be compatible with Carbon\Carbon::diffForHumans HOT 5
- Laravel 5.4 Support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from localized-carbon.