Giter Site home page Giter Site logo

Comments (11)

ocombe avatar ocombe commented on May 21, 2024 9

You should either use [title]="'HELLO' | translate" or title="{{ 'HELLO' | translate }}", but [title]="{{ 'HELLO' | translate }}" is not correct Angular

from core.

ocombe avatar ocombe commented on May 21, 2024 3

You're supposed to use your key, something like that:

<ion-refresher pullingText="{{ 'PULL' | translate }}">

And then you define the translation in your json file (or you manually) like that: "PULL": "Pull to refresh..."

In this case "PULL" is the key, and "Pull to refresh..." is your translation.

from core.

ocombe avatar ocombe commented on May 21, 2024 3
fetchTranslation(key: string, params = {}) {
    return this.translate.instant(key, params);
}

or you could just use the service:

[title]="translate.instant('HELLO')"

But be careful because if you use the change detection OnPush this will not update your view, you should use the pipe or directive for that.

from core.

ocombe avatar ocombe commented on May 21, 2024 1

no, it's in the docs: https://github.com/ngx-translate/core#methods

from core.

ZigaVukcevicDev avatar ZigaVukcevicDev commented on May 21, 2024

I apologise, this was an error triggered by some other issue.

from core.

ZigaVukcevicDev avatar ZigaVukcevicDev commented on May 21, 2024

@ocombe it also works with hardcoded string.

from core.

elliotwesoff avatar elliotwesoff commented on May 21, 2024

What if we have the HTML attribute tied to a component property? For example...

[title]="{{ 'HELLO' | translate }}"

Or even using a method like this in the component doesn't work for me. It just puts undefined in the view:

[title]="fetchTranslation('HELLO')"

fetchTranslation(key: string, params = {}) {
    this.translate.get(key, params).subscribe((res: string) => {
        return res;
    });
}

from core.

elliotwesoff avatar elliotwesoff commented on May 21, 2024

Got it. Thanks for the quick reply! :) any idea how to get the service thing working though? That would really help with keeping the views tidy.

from core.

elliotwesoff avatar elliotwesoff commented on May 21, 2024

Worked like a charm! Thank you 👍

By the way, is there any extra documentation available? Like would I have needed to read the source to find out about that method?

from core.

cryptoplastic avatar cryptoplastic commented on May 21, 2024

I have the above working, but I become stuck when using data-title on tables.

data-title="{{fetchTranslation('name')}}"

for example does not work.

Is there a was to get this working with data-title? This is a key property for displaying data on mobile.

from core.

chaimmw avatar chaimmw commented on May 21, 2024

I had this problem,
[title]="'Location' | translate" shows a tool-tip

but,

[title]="'Historical Development' | translate" does not show a tool-tip
same for
title="{{ 'Historical Development' | translate}}"
but when I remove the translate pipe -
title="'Historical Development'" does show a tool-tip

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.