New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numbers as translation keys #36

Closed
sandstrom opened this Issue Nov 9, 2010 · 6 comments

Comments

Projects
None yet
6 participants
@sandstrom

sandstrom commented Nov 9, 2010

Would be neat if this worked. Ran into it setting up translations for different error pages (404, 500 etc.)

>> I18n.t "test"
=> {100=>"dont work", :hundred=>"works"}
>> I18n.t "test.100"
=> "translation missing: sv, test, 100"
>> I18n.t "test.hundred"
=> "works"
@kuroda

This comment has been minimized.

Show comment
Hide comment
@kuroda

kuroda Nov 9, 2010

Collaborator

Hi, sandstrom

Please post this on https://github.com/svenfuchs/i18n/issues.

Here is just the repository of locale data.

Thanks.

Collaborator

kuroda commented Nov 9, 2010

Hi, sandstrom

Please post this on https://github.com/svenfuchs/i18n/issues.

Here is just the repository of locale data.

Thanks.

@svenfuchs

This comment has been minimized.

Show comment
Hide comment
@svenfuchs

svenfuchs Nov 9, 2010

Owner

sandstrom, this is a limitation of YAML, not I18n. You can try quoting the numbers though:

>> YAML.load('{ "100": works }')
=> {"100"=>"works"}
Owner

svenfuchs commented Nov 9, 2010

sandstrom, this is a limitation of YAML, not I18n. You can try quoting the numbers though:

>> YAML.load('{ "100": works }')
=> {"100"=>"works"}
@sandstrom

This comment has been minimized.

Show comment
Hide comment
@sandstrom

sandstrom Nov 11, 2010

Great, thanks!

sandstrom commented Nov 11, 2010

Great, thanks!

@rathgar

This comment has been minimized.

Show comment
Hide comment
@rathgar

rathgar May 19, 2013

Just in case anyone finds this issue and is still looking for an answer, symbolising the number will help it work with I18n:

en:
  http:
    error:
      :404: Not found.
      ...
> I18n.t('http.error.404') 
#=> "Not found."

rathgar commented May 19, 2013

Just in case anyone finds this issue and is still looking for an answer, symbolising the number will help it work with I18n:

en:
  http:
    error:
      :404: Not found.
      ...
> I18n.t('http.error.404') 
#=> "Not found."
@barnett

This comment has been minimized.

Show comment
Hide comment
@barnett

barnett commented Oct 13, 2015

thanks @rathgar!

@12finger

This comment has been minimized.

Show comment
Hide comment
@12finger

12finger Sep 26, 2017

for anyone looking into using this stuff with a React.js frontend ... use the String version of it:

en:
  http:
    error:
      "404": Not found.
      ...

as the symbolising approach seems to not make it properly into the language files compiled for React.

so you can do a:

import React, { Component } from 'react'
import t from '../../constants/Locales'

class Heading extends Component {
    render() {
        return(
            <div className="heading">
                <span>{this.props.index}</span>
                {t(`http.error.${this.props.index}`)}
            </div>
        )
    }
}

export default Heading

12finger commented Sep 26, 2017

for anyone looking into using this stuff with a React.js frontend ... use the String version of it:

en:
  http:
    error:
      "404": Not found.
      ...

as the symbolising approach seems to not make it properly into the language files compiled for React.

so you can do a:

import React, { Component } from 'react'
import t from '../../constants/Locales'

class Heading extends Component {
    render() {
        return(
            <div className="heading">
                <span>{this.props.index}</span>
                {t(`http.error.${this.props.index}`)}
            </div>
        )
    }
}

export default Heading

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment