How to use variables in markups?

13 views
Skip to first unread message

Mahmoud Abdel-Fattah

unread,
May 24, 2014, 7:41:26 PM5/24/14
to ang...@googlegroups.com
I'm working on a bilingual app, and want to call the markup depends on current language.

So, I have a variable called "lang", now how can I call {{name+lang}}? it should be either {{name_en}} or {{name_ar}

Rafael Bernard Rodrigues Araujo

unread,
May 24, 2014, 7:56:21 PM5/24/14
to ang...@googlegroups.com
Mahmoud, I think you can use angular i18n for this.
https://docs.angularjs.org/guide/i18n
http://angular-translate.github.io/
On Sat, May 24, 2014 at 8:41 PM, Mahmoud Abdel-Fattah <mah...@abdel-fattah.net> wrote:
I'm working on a bilingual app, and want to call the markup depends on current language.

So, I have a variable called "lang", now how can I call {{name+lang}}? it should be either {{name_en}} or {{name_ar}

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Mahmoud Abdel-Fattah

unread,
May 24, 2014, 8:07:13 PM5/24/14
to ang...@googlegroups.com

Thank you Rafael, but I am already using angular translate for the static language variables. Now, I want to use variable in the markup.

MAF on the move!

You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/WP1FU0HQlGQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

Daphne Maddox

unread,
May 25, 2014, 2:01:08 AM5/25/14
to ang...@googlegroups.com
If you are working on a multilingual app you should really look at http://angular-translate.github.io/

If you really want to do what you're asking, you could do:

    <span>{{lastNames['en_US']['daphne']}}</span>

and in your controller you could create a two-level hash object like this:

      $scope.lastNames = {
        'en_US': {
          'daphne': 'maddox'
        }
      };

That will work, but you'd basically be reinventing Angular Translate at that point, without all of the great usability that it provides.

Or, to be completely literal to your question, if you want this to be your html template:

    <span>{{name_en}}</span>
    <span>{{name_ar}}</span>

then in your controller you could say:

      $scope.name_en = 'abc';
      $scope.name_ar = '123';

but it seems unlikely that that is really what you're trying to do... anywhere there it is if so.

Reply all
Reply to author
Forward
0 new messages