how to localize array value on the html page

48 views
Skip to first unread message

arava

unread,
Nov 29, 2018, 7:05:04 AM11/29/18
to Fat-Free Framework
hi everyone.
I have the next structure: 
en.php
return = [
   'processing' => 'some state',
];
------------------------------------------
SomeController.php
$value = 'processing';

$this-f3->set('state',$value);
------------------------------------------
some_html.html

{{ @state }}
------------------------------------------
// okay, the state value is processing... it`s fine... But how i should translate this value into another lang ??? I know how to enable localization in F3, but how to do this with a value that is already under template engine...
i mean something like this :

{{ @ {{@state }}


thx

ved

unread,
Nov 29, 2018, 8:22:36 AM11/29/18
to Fat-Free Framework
Hi, not sure I understood your issue correctly but maybe you can try to do something like this:

On your language files:

return [
   
'statetypes' => [
       
'processing' => 'processing translation',
       
'complete' => 'complete translation'
   
]
];

And then on your view:

{{ @statetypes[@state] }}

Hope it helps, but let me know if this was not what you were asking for.

Good luck.

Richard Goldstein

unread,
Nov 29, 2018, 8:27:21 AM11/29/18
to Fat-Free Framework

Also a reminder – don’t forget to set ‘LOCALES’ and ‘FALLBACK’ if necessary

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/2633e96c-1b98-43ad-8efd-ed071940e3e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yaroslav Beregovoy

unread,
Nov 29, 2018, 8:53:40 AM11/29/18
to f3-framework+APn2wQdk8BzurMhBnm1...@googlegroups.com
that`s pretty good, in this case it`s work... thank you a lot)

in the next part we are talking about dynamic data, not static...
so, if i correctly understood there is only one way to translate the value if this value transfer from controller into html...
Because if i set the value from controller like $this->f3->set('value','processing); than if i need to display it i have to do the next one:
{{ @value }} and it will display 'processing' for me... but f3 do not translate 'processing' into another lang, for example RU

so, does not work with this lang structure:
return = [
  'processing' => 'some word in other land',
];
and work fine with this :
return = [
  '_states' => ['processing' => 'some word']
];
{{ @_states[@value] }}

thank`s a much again, cheers



--

ikkez

unread,
Nov 29, 2018, 1:14:51 PM11/29/18
to f3-fra...@googlegroups.com
just tested and seems to work:


{{ ${@state} }}


but having them sorted into another array is probably more clean, so I would go with it like you have solved it now... it's just for the completeness here

Yaroslav Beregovoy

unread,
Nov 29, 2018, 1:22:11 PM11/29/18
to f3-framework+APn2wQcLLxvM44tXyXU...@googlegroups.com
that`s right, it`s work... but i never saw this syntax, can you give me please where i can find it in docs ?

On Thu, Nov 29, 2018 at 8:14 PM ikkez via Fat-Free Framework <f3-framework+APn2wQcLLxvM44tXyXU...@googlegroups.com> wrote:
just tested and seems to work:


{{ ${@state} }}


Am Donnerstag, 29. November 2018 13:05:04 UTC+1 schrieb arava:
hi everyone.
I have the next structure: 
en.php
return = [
   'processing' => 'some state',
];
------------------------------------------
SomeController.php
$value = 'processing';

$this-f3->set('state',$value);
------------------------------------------
some_html.html

{{ @state }}
------------------------------------------
// okay, the state value is processing... it`s fine... But how i should translate this value into another lang ??? I know how to enable localization in F3, but how to do this with a value that is already under template engine...
i mean something like this :

{{ @ {{@state }}


thx

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.

ikkez

unread,
Nov 29, 2018, 1:25:35 PM11/29/18
to Fat-Free Framework
Also, if you use a language PREFIX, like i.e.

PREFIX = ll.

then you could simplify it within your templates like:

{{ @ll[@state] }}

and this way you also have seperated your language keys from the rest of your hive variables. I think that's important.

the syntax from above is simple php.. since everything in {{ }} can be a php expression, you simply write ${$foo}, which is a dynamic variable.. same like $foo->{$bar} being a dynamic object property or $foo[$bar] a dynamic array key.


Am Donnerstag, 29. November 2018 19:22:11 UTC+1 schrieb arava:
that`s right, it`s work... but i never saw this syntax, can you give me please where i can find it in docs ?

On Thu, Nov 29, 2018 at 8:14 PM ikkez via Fat-Free Framework <f3-framework+APn2wQcLLxvM44tXyXUIlLiBuahXNKnThidSJJEimHzvX0ckDZq@googlegroups.com> wrote:
just tested and seems to work:


{{ ${@state} }}


Am Donnerstag, 29. November 2018 13:05:04 UTC+1 schrieb arava:
hi everyone.
I have the next structure: 
en.php
return = [
   'processing' => 'some state',
];
------------------------------------------
SomeController.php
$value = 'processing';

$this-f3->set('state',$value);
------------------------------------------
some_html.html

{{ @state }}
------------------------------------------
// okay, the state value is processing... it`s fine... But how i should translate this value into another lang ??? I know how to enable localization in F3, but how to do this with a value that is already under template engine...
i mean something like this :

{{ @ {{@state }}


thx

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en

---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework+unsubscribe@googlegroups.com.

Yaroslav Beregovoy

unread,
Nov 29, 2018, 1:33:27 PM11/29/18
to f3-framework+APn2wQcLLxvM44tXyXU...@googlegroups.com
i am thankful :-)

On Thu, Nov 29, 2018 at 8:25 PM ikkez via Fat-Free Framework <f3-framework+APn2wQcLLxvM44tXyXU...@googlegroups.com> wrote:
Also, if you use a language PREFIX, like i.e.

PREFIX = ll.

then you could simplify it within your templates like:

{{ @ll[@state] }}

and this way you also have seperated your language keys from the rest of your hive variables. I think that's important.

the syntax from above is simple php.. since everything in {{ }} can be a php expression, you simply write ${$foo}, which is a dynamic variable.. same like $foo->{$bar} being a dynamic object property or $foo[$bar] a dynamic array key.


Am Donnerstag, 29. November 2018 19:22:11 UTC+1 schrieb arava:
that`s right, it`s work... but i never saw this syntax, can you give me please where i can find it in docs ?

On Thu, Nov 29, 2018 at 8:14 PM ikkez via Fat-Free Framework <f3-framework+APn2wQcLLxvM44tXyXU...@googlegroups.com> wrote:
just tested and seems to work:


{{ ${@state} }}


Am Donnerstag, 29. November 2018 13:05:04 UTC+1 schrieb arava:
hi everyone.
I have the next structure: 
en.php
return = [
   'processing' => 'some state',
];
------------------------------------------
SomeController.php
$value = 'processing';

$this-f3->set('state',$value);
------------------------------------------
some_html.html

{{ @state }}
------------------------------------------
// okay, the state value is processing... it`s fine... But how i should translate this value into another lang ??? I know how to enable localization in F3, but how to do this with a value that is already under template engine...
i mean something like this :

{{ @ {{@state }}


thx

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en

---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en

---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.

To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.

ved

unread,
Nov 29, 2018, 2:31:20 PM11/29/18
to Fat-Free Framework
Good catch, I forgot about PREFIX.
But yes, this is the best and cleaner solution for this issue imho.
Reply all
Reply to author
Forward
0 new messages