admin管理员组文章数量:1516870
So I am trying to make these strings translatable and in proper PHP/WP format. This works:
'Du ' . date_i18n( 'j M', strtotime( $date_debut->format('j M Y') ) ) . ' au ' . date_i18n( get_option( 'date_format' ), strtotime( $date_fin->format('j M Y') ) );
The equivalent using printf should be something like this:
printf(
__( 'Du %1$s au %2$s', 'my-plugin' ),
date_i18n( 'j M', strtotime( $date_debut->format('j M Y') ) ),
date_i18n( get_option( 'date_format' ), strtotime( $date_fin->format('j M Y') ) )
);
But for some reason the Year comes out as either 201914 or 201920.
Why are there extra characters on the dates?
EDIT
The results are fine and as expected when using without the printf() function
__('Du ' . date_i18n( 'j M', strtotime( $date_de_debut ) ) . ' au ' . date_i18n( get_option( 'date_format' ), strtotime( $date_de_fin ) ) );
So I am trying to make these strings translatable and in proper PHP/WP format. This works:
'Du ' . date_i18n( 'j M', strtotime( $date_debut->format('j M Y') ) ) . ' au ' . date_i18n( get_option( 'date_format' ), strtotime( $date_fin->format('j M Y') ) );
The equivalent using printf should be something like this:
printf(
__( 'Du %1$s au %2$s', 'my-plugin' ),
date_i18n( 'j M', strtotime( $date_debut->format('j M Y') ) ),
date_i18n( get_option( 'date_format' ), strtotime( $date_fin->format('j M Y') ) )
);
But for some reason the Year comes out as either 201914 or 201920.
Why are there extra characters on the dates?
EDIT
The results are fine and as expected when using without the printf() function
__('Du ' . date_i18n( 'j M', strtotime( $date_de_debut ) ) . ' au ' . date_i18n( get_option( 'date_format' ), strtotime( $date_de_fin ) ) );
Share
Improve this question
edited May 21, 2019 at 14:25
MediaFormat
asked May 17, 2019 at 19:46
MediaFormatMediaFormat
2831 silver badge11 bronze badges
3
- 1 What’s the result of __() function for this string? Could you var_dump it? – Krzysiek Dróżdż Commented May 18, 2019 at 7:54
- Good call, I’ll check on Monday! – MediaFormat Commented May 18, 2019 at 12:28
- @KrzysiekDróżdż thanks, I was using the wrong formatting function! – MediaFormat Commented May 21, 2019 at 14:05
1 Answer
Reset to default 0Because the translate function __() worked fine, I suspected printf() was the culprit.
Turns out sprintf() is what I needed! printf() arguments work differently
本文标签: printftranslation function and datei18n adds extra characters
版权声明:本文标题:printf, translation function and date_i18n adds extra characters 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/web/1745477056a2660008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论