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

How to customize local strings #167

Open
Anisi opened this issue Mar 4, 2019 · 7 comments
Open

How to customize local strings #167

Anisi opened this issue Mar 4, 2019 · 7 comments

Comments

@Anisi
Copy link

Anisi commented Mar 4, 2019

Hi
Could you please tell me what have I to do if I want to customize local strings like relativeTime?

@alitaheri
Copy link
Member

@Anisi This library is based on the standard moment.js API, in other words this guide should work for you:

https://momentjs.com/docs/#/customization/relative-time/

let me know if you fail to get it working.

@Anisi
Copy link
Author

Anisi commented Mar 4, 2019

Thank you for your quick response
Yes, I tried it before. This solution works on original moment.js but doesn't work on Jalali distribution.

@alitaheri
Copy link
Member

It should. are you calling loadPersian and then immediately calling your own updateLocale? if that doesn't fix it, please share the code so I can investigate.

@Anisi
Copy link
Author

Anisi commented Mar 5, 2019

Yeah! it should, but it doesn't.
This is my code:

moment.loadPersian({usePersianDigits: true});
moment.updateLocale('fa', {
    relativeTime: {
        future: "تا %s",
        past: "%s ago",
        s: 'چند ثانیه',
        ss: '%d ثانیه',
        m: "یک دقیقه",
        mm: "%d دقیقه",
        h: "یک ساعت",
        hh: "%d ساعت",
        d: "یک روز",
        dd: "%d روز",
        M: "یک ماه",
        MM: "%d ماه",
        y: "یک سال",
        yy: "%d سال"
    }
});

let momentFa = moment;

export {momentFa};
render() {
        const openingTime = this.state.summarise ? this.state.summarise.order_time_period.order_opening_time : null;
        const closingTime = this.state.summarise ? this.state.summarise.order_time_period.order_closing_time : null;
        const serverTime = this.state.summarise ? this.state.summarise.server_time : null;
        const inOrderTime = openingTime && closingTime ? momentFa(serverTime).isBetween(momentFa(openingTime), momentFa(closingTime)) : false;

        const timeToOpening = serverTime ? momentFa(serverTime).to(openingTime) : '';
        return (
            !inOrderTime &&
            <aside id="opening-bar">
                <h3><i className="icon icon-clock"></i> {timeToOpening} دیگه می‌تونین سفارش بدین</h3>
            </aside>
        )
    }

Example output:

در 1 دقیقه دیگه می‌تونین سفارش بدین

But should be:

تا یک دقیقه دیگه می‌تونین سفارش بدین

@alitaheri
Copy link
Member

I also need and example of how you're testing this. like expected output... actual output...

@Anisi
Copy link
Author

Anisi commented Mar 5, 2019

I also need and example of how you're testing this. like expected output... actual output...

Added new details

@alitaheri
Copy link
Member

alitaheri commented Mar 5, 2019

There must be something wrong with the way you've set up your project. this is a my output:

image

investigate your versions and try to trace the code inside the functions and see what objects are being used. I copied your code and it works with the latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants