Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted April 10, 20168 yr 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?
April 10, 20168 yr Probably you need something like: {{$day1 = \IPS\Member::loggedIn()->language()->addToStack( 'day_' . date( 'w', $timestamp ) . '_short' );}} addToStack or get. Untested.
April 10, 20168 yr 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}"}
April 10, 20168 yr 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="".
April 11, 20168 yr Author @Adriano Faria I get day_2_short string in the output, so I guess the problem is in the second part: how {lang=""} works.
April 11, 20168 yr 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?
April 11, 20168 yr 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
April 11, 20168 yr Author 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?
April 11, 20168 yr 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.
April 11, 20168 yr Author 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.
April 14, 20168 yr 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).
Archived
This topic is now archived and is closed to further replies.