Skip to content
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

ToQuantity / Ordinalize / ToOrdinalWords / ToWords should do nothing for unsupported languages. #132

Closed
hazzik opened this issue Apr 7, 2014 · 12 comments
Labels

Comments

@hazzik
Copy link
Member

hazzik commented Apr 7, 2014

No description provided.

@hazzik hazzik changed the title ToQuantity / Ordinalize should do nothing for unsupported languages. ToQuantity / Ordinalize / ToOrdinalWords / ToWords should do nothing for unsupported languages. Apr 7, 2014
@MehdiK
Copy link
Member

MehdiK commented Apr 7, 2014

Thanks for raising this @hazzik. Yeah, we should fix this soon.

@MehdiK
Copy link
Member

MehdiK commented Apr 10, 2014

I think this should be fixed by #149; but we need to write some tests to verify and enforce this.

@hazzik
Copy link
Member Author

hazzik commented Apr 10, 2014

I'm trying to implement the tests, but I can not decide which culture to use as "unknown"

@MehdiK
Copy link
Member

MehdiK commented Apr 10, 2014

Maybe "dc-DummyCulture"?!

@MehdiK
Copy link
Member

MehdiK commented Apr 10, 2014

CultureInfo might crap out on that though! ;)

@hazzik
Copy link
Member Author

hazzik commented Apr 10, 2014

.NET throws "Unsupported culture" exception.

@hazzik
Copy link
Member Author

hazzik commented Apr 10, 2014

I think CultureInfo.InvariantCulture is good, isnt it?

@MehdiK
Copy link
Member

MehdiK commented Apr 10, 2014

But that's English too, right? I don't know. Give that a shot. If it doesn't work, we can pick a culture with no existing localisation here and push this up. We can deal with that culture later if it ever pops up.

@hazzik
Copy link
Member Author

hazzik commented Apr 10, 2014

But that's English too

Not exactly, it has own language code (iv/IVL), but for resources it will select the neutral resource (which is English)

@MehdiK
Copy link
Member

MehdiK commented Apr 10, 2014

ah, cool. Thanks. Go for it then :)

@MehdiK
Copy link
Member

MehdiK commented Apr 11, 2014

To verify this you could change the Invariant\ToQuantityTests to:

    public class ToQuantityTests 
    {
        [Theory]
        [InlineData("case", 0, "0 cases")]
        [InlineData("case", 1, "1 case")]
        [InlineData("case", 5, "5 cases")]
        [InlineData("man", 0, "0 men")]
        [InlineData("man", 1, "1 man")]
        [InlineData("man", 2, "2 men")]
        [InlineData("men", 2, "2 men")]
        [InlineData("process", 2, "2 processes")]
        [InlineData("process", 1, "1 process")]
        [InlineData("processes", 2, "2 processes")]
        [InlineData("processes", 1, "1 process")]
        public void ToQuantity(string word, int quatity, string expected)
        {
            using(new AmbientCulture(CultureInfo.InvariantCulture))
                Assert.Equal(expected, word.ToQuantity(quatity));

            using (new AmbientCulture("ar"))
                Assert.Equal(expected, word.ToQuantity(quatity));

            using (new AmbientCulture("fa"))
                Assert.Equal(expected, word.ToQuantity(quatity));
        }

        [Theory]
        [InlineData("case", 0, "cases")]
        [InlineData("case", 1, "case")]
        [InlineData("case", 5, "cases")]
        [InlineData("man", 0, "men")]
        [InlineData("man", 1, "man")]
        [InlineData("man", 2, "men")]
        [InlineData("men", 2, "men")]
        [InlineData("process", 2, "processes")]
        [InlineData("process", 1, "process")]
        [InlineData("processes", 2, "processes")]
        [InlineData("processes", 1, "process")]
        public void ToQuantityWithNoQuantity(string word, int quatity, string expected)
        {
            using (new AmbientCulture(CultureInfo.InvariantCulture))
                Assert.Equal(expected, word.ToQuantity(quatity, ShowQuantityAs.None));

            using (new AmbientCulture("ar"))
                Assert.Equal(expected, word.ToQuantity(quatity, ShowQuantityAs.None));

            using (new AmbientCulture("fa"))
                Assert.Equal(expected, word.ToQuantity(quatity, ShowQuantityAs.None));
        }

        [Theory]
        [InlineData("case", 0, "0 cases")]
        [InlineData("case", 1, "1 case")]
        [InlineData("case", 5, "5 cases")]
        [InlineData("man", 0, "0 men")]
        [InlineData("man", 1, "1 man")]
        [InlineData("man", 2, "2 men")]
        [InlineData("men", 2, "2 men")]
        [InlineData("process", 2, "2 processes")]
        [InlineData("process", 1, "1 process")]
        [InlineData("processes", 2, "2 processes")]
        [InlineData("processes", 1, "1 process")]
        public void ToQuantityNumeric(string word, int quatity, string expected)
        {
            // ReSharper disable RedundantArgumentDefaultValue
            using (new AmbientCulture(CultureInfo.InvariantCulture))
                Assert.Equal(expected, word.ToQuantity(quatity, ShowQuantityAs.Numeric));

            using (new AmbientCulture("ar"))
                Assert.Equal(expected, word.ToQuantity(quatity, ShowQuantityAs.Numeric));

            using (new AmbientCulture("fa"))
                Assert.Equal(expected, word.ToQuantity(quatity, ShowQuantityAs.Numeric));
            // ReSharper restore RedundantArgumentDefaultValue
        }

        [Theory]
        [InlineData("case", 0, "0 cases")]
        [InlineData("case", 1, "1 case")]
        [InlineData("case", 5, "5 cases")]
        [InlineData("man", 0, "0 men")]
        [InlineData("man", 1, "1 man")]
        [InlineData("man", 2, "2 men")]
        [InlineData("men", 2, "2 men")]
        [InlineData("process", 2, "2 processes")]
        [InlineData("process", 1, "1 process")]
        [InlineData("processes", 2, "2 processes")]
        [InlineData("processes", 1200, "1200 processes")]
        [InlineData("processes", 1, "1 process")]
        public void ToQuantityWords(string word, int quatity, string expected)
        {
            using (new AmbientCulture(CultureInfo.InvariantCulture))
                Assert.Equal(expected, word.ToQuantity(quatity, ShowQuantityAs.Words));

            using (new AmbientCulture("ar"))
                Assert.Equal(expected, word.ToQuantity(quatity, ShowQuantityAs.Words));

            using (new AmbientCulture("fa"))
                Assert.Equal(expected, word.ToQuantity(quatity, ShowQuantityAs.Words));
        }
    }

@MehdiK
Copy link
Member

MehdiK commented Apr 26, 2014

This is fixed by #162

@MehdiK MehdiK closed this as completed Apr 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants