Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
motomac Posted April 10, 2016 Posted April 10, 2016 I need to get short weekday names dynamically. But this code in templates doesn't work: {{$day1 = 'day_' . date( 'w', $timestamp ) . '_short';}} {lang="$day1"} Is it possible to do this?
Adriano Faria Posted April 10, 2016 Posted April 10, 2016 Probably you need something like: {{$day1 = \IPS\Member::loggedIn()->language()->addToStack( 'day_' . date( 'w', $timestamp ) . '_short' );}} addToStack or get. Untested.
HeadStand Posted April 10, 2016 Posted April 10, 2016 2 hours ago, motomac said: I need to get short weekday names dynamically. But this code in templates doesn't work: {{$day1 = 'day_' . date( 'w', $timestamp ) . '_short';}} {lang="$day1"} Is it possible to do this? Edit: scratch what I said before. What you want is {lang="{$day1}"}
HeadStand Posted April 10, 2016 Posted April 10, 2016 8 hours ago, Adriano Faria said: Probably you need something like: {{$day1 = \IPS\Member::loggedIn()->language()->addToStack( 'day_' . date( 'w', $timestamp ) . '_short' );}} addToStack or get. Untested. addToStack is actually the equivalent of lang="".
motomac Posted April 11, 2016 Author Posted April 11, 2016 @HeadStand I tried this, but without success.
motomac Posted April 11, 2016 Author Posted April 11, 2016 @Adriano Faria I get day_2_short string in the output, so I guess the problem is in the second part: how {lang=""} works.
HeadStand Posted April 11, 2016 Posted April 11, 2016 23 minutes ago, motomac said: @Adriano Faria I get day_2_short string in the output, so I guess the problem is in the second part: how {lang=""} works. lang makes a call to addToStack. So the question is, do you have a language string called day_2_short?
motomac Posted April 11, 2016 Author Posted April 11, 2016 @HeadStand yes, sure, I have it. As I know, it's a default string.
Daniel F Posted April 11, 2016 Posted April 11, 2016 17 minutes ago, motomac said: @HeadStand yes, sure, I have it. As I know, it's a default string. No, it's a js language string, which means that it doesn't exist in the php scope
motomac Posted April 11, 2016 Author Posted April 11, 2016 6 hours ago, Daniel F said: No, it's a js language string, which means that it doesn't exist in the php scope Hm... But I can see it in the ACP: What should I do now?
HeadStand Posted April 11, 2016 Posted April 11, 2016 2 hours ago, motomac said: Hm... But I can see it in the ACP: What should I do now? It will be listed in the ACP because that would display both PHP and JS variables. You'll need to create duplicate strings in your own lang file.
motomac Posted April 11, 2016 Author Posted April 11, 2016 Is there any way to avoid this duplication? I don't want to let the users of my plugin to translate these strings while they are already translated in the System.
bfarber Posted April 14, 2016 Posted April 14, 2016 On 4/10/2016 at 10:21 AM, motomac said: I need to get short weekday names dynamically. But this code in templates doesn't work: {{$day1 = 'day_' . date( 'w', $timestamp ) . '_short';}} {lang="$day1"} Is it possible to do this? So you have a variable $timestamp which, presumably, holds a timestamp right? And you want to show the short form of the day (i.e. "Sun" for Sunday)? Something like this should work {expression="\IPS\DateTime::ts( $timestamp )->strFormat( '%a' )"} This doesn't rely on language strings but rather uses the native PHP DateTime object (which is locale aware).
Recommended Posts
Archived
This topic is now archived and is closed to further replies.