opening-hours / opening_hours.js

Library to parse and process the opening_hours tag from OpenStreetMap data
https://openingh.ypid.de/evaluation_tool/
222 stars 119 forks source link

Allow internationalization of value returned by oh.prettifyValue() #90

Closed amenk closed 9 years ago

amenk commented 9 years ago

The library is also useful for non-OSM-used where the opening times are in a local language.

It would be great if it was possible to translate SH / PH / Weekdays / Monthnamess in a local language by specifying a locale.

ypid commented 9 years ago

Already possible, no need to rewrite the input tolerance feature of opening_hours.js :smile:

See https://github.com/ypid/opening_hours.js/blob/e57b1b65dcbf73b88d3b309db9f130722ad706ee/opening_hours.js#L2919

Note that a warning will be generated in case keywords are used not covered by the spec. Just ignore warnings when in non-OSM use cases.

amenk commented 9 years ago

Good point. But I would like to have a prettified string also with the German codes... But I might be able to omit that.

ypid commented 9 years ago

I am also a native German speaker so German is already quite well supported I think.

Montag-Freitag von 10.00 bis 20.00; Schulferien,Sonn- und Feiertage geschlossen

amenk commented 9 years ago

I know guessed you are :) But it does not allow to generate a prettified string in German. What I could do is to ignore all warnings and then after prettifying replace "We" by "Mi" and so on. That might work but not sure if it is that clean?

ypid commented 9 years ago

Simple string replacement is discouraged of course :) For that use case I would recommend to get the tokens array and replace it there. See the demo.html for an example (#47).

amenk commented 9 years ago

how exactly? I can't find any example of such in the demo.html

ypid commented 9 years ago

Search for prettified_value_array in demo.html.

amenk commented 9 years ago

But then I have to rebuild the string from the array... duplicating half of prettifyValue() ... hm

ypid commented 9 years ago

If you can hack up prettifyValue() to return a nice German representation of the opening hours why not. prettifyValue() can be configured via the conf parameter. You can add a new conf option like 'locale' and then include it into opening_hours.js.

amenk commented 9 years ago

okay I will try. Could be integrated with the t() function I guess

ypid commented 9 years ago

Could be integrated with t(). But I am not sure if this would be a big advantage. It is probably better/simpler to define a hash with all the locales in it something like:

var prettified_value_locales = {
    'de': {
        'weekday': {
            'mo': 'Montag',
        }
    }
}

It probably does not make sense to integrate it with word_error_correction, not sure …

amenk commented 9 years ago

But I thought you do not want to increase the size of the opening_hours.js so much? Or this hash you suggest could be included in the lang file as well ..

ypid commented 9 years ago

The hash prettified_value_locales could later be moved to it’s own JS module.

OK, right. This (i18next) might be better in that case. suncalc as an example can also be used by opening_hours.js to have additional features. You can try it with i18next.

amenk commented 9 years ago

or we can use moment's i18n ?

ypid commented 9 years ago

Right, almost forgot moment’s … Yes, that would be the best option to start with. Maybe #65 should be solved first so that this project can use the current version (defined in package.json) …

amenk commented 9 years ago

Here it is

ypid commented 9 years ago

When you are done can you open a PR. I will have a closer look tonight.

amenk commented 9 years ago

There are in #89 lots of messages still to be extracted / translated. Would you have time to do this? Or maybe I can find some colleague. I probably will not have time for it.

ypid commented 9 years ago

Unfortunately this feature is not very high on my priority list and it is a hobby project. If I get funded I would be more than happy to do it :smile:

amenk commented 9 years ago

I think I will do it :-)

amenk commented 9 years ago

is finished. Can you merge?