Giter Site home page Giter Site logo

string with parameters about i18n HOT 5 CLOSED

turquoiseowl avatar turquoiseowl commented on August 15, 2024
string with parameters

from i18n.

Comments (5)

raulvejar avatar raulvejar commented on August 15, 2024

Mmmm... i don't think it will produce the right pot entry unless it's static text. Depending on what you insert as a parameter then the syntax would change for some languages (for example languages where nouns have gender). Translators would need more context to translate appropiately.
If you are planning on putting constant variables anyways why would you need to parametize it?

from i18n.

juanl avatar juanl commented on August 15, 2024

Sorry, maybe I've not explained properly. When I said:
__("Hello {0}!", "juan") or __("you've earned {0} point of {1}", 1, 10)
I've try to say:
__("Hello {0}!", session["name"])
__("you've earned {0} point of {1}", pointsEarned, TotalPoints)

These are not constant variables...

I've dealed with this in other platforms and of course, always translators need a good context to translate any string appropiately....

Best
Juan

from i18n.

turquoiseowl avatar turquoiseowl commented on August 15, 2024

Seems like a good idea. xgettext will pick up okay the __() function calls with more than one argument, so it should work fine.

As to what gettext/PO best practice is for what you want, can't comment but there is stuff in the spec on how to do it.

from i18n.

turquoiseowl avatar turquoiseowl commented on August 15, 2024

There is stuff in the spec about plurals which I don't think this library supports right now.

from i18n.

turquoiseowl avatar turquoiseowl commented on August 15, 2024

Here's quite a nice example of a localized and parameterized HTML 'title' attribute being generated using razor and i18n v2.0:

  using (Html.BeginForm("ExternalSignin", "Account", new { ReturnUrl = ViewBag.ReturnUrl })) {
    @Html.AntiForgeryToken()
    <fieldset>
      <legend>[[[Sign in using another service]]]</legend>
      @foreach (AuthenticationClientData p in Model) {
        <button
          class="low" 
          type="submit"
          name="provider" 
          value="@p.AuthenticationClient.ProviderName"
          @_("Sign up or in using your {0} account", "title", p.DisplayName)
          >@p.DisplayName</button>
      }
    </fieldset>
  }

And for fun, an alternative way of doing the same thing using the proposed 'nugget' feature:

  using (Html.BeginForm("ExternalSignin", "Account", new { ReturnUrl = ViewBag.ReturnUrl })) {
    @Html.AntiForgeryToken()
    <fieldset>
      <legend>[[[Sign in using another service]]]</legend>
      @foreach (AuthenticationClientData p in Model) {
        <button
          class="low" 
          type="submit"
          name="provider" 
          value="@p.AuthenticationClient.ProviderName"
          title="@string.Format("[[[Sign up or in using your %0 account|||{0}]]]", p.DisplayName)"
          >@p.DisplayName</button>
      }
    </fieldset>
  }

Note that this is in the v2.0 branch, not master at the moment.

from i18n.

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.