Modify

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#11755 closed enhancement (fixed)

Update to new version of opening_hours.js.

Reported by: ypid23 Owned by: simon04
Priority: normal Milestone: 15.09
Component: Core validator Version:
Keywords: javascript nodejs module require rhino nashorn java7 java8 Cc:

Description

Hi

I just released v3.3.0 of opening_hours.js which adds German translations for all error messages and some warning messages. I guess this can be quite helpful. In order to use this feature, you need to update the library and adopt the opening_hours constructor parameters. Note that this feature has some dependencies. Check the example below.

#!/usr/bin/env nodejs

var nominatiomTestJSON = {"place_id":"44651229","licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright","osm_type":"way","osm_id":"36248375","lat":"49.5400039","lon":"9.7937133","display_name":"K 2847, Lauda-K\u00f6nigshofen, Main-Tauber-Kreis, Regierungsbezirk Stuttgart, Baden-W\u00fcrttemberg, Germany, European Union","address":{"road":"K 2847","city":"Lauda-K\u00f6nigshofen","county":"Main-Tauber-Kreis","state_district":"Regierungsbezirk Stuttgart","state":"Baden-W\u00fcrttemberg","country":"Germany","country_code":"de","continent":"European Union"}};

var locale_example = 'de';

var opening_hours = require('opening_hours');
i18n = require('i18next');
moment = require('moment');
var i18n_res = require('./locales/core.js');

i18n.setLng(locale_example, function(err, t) { /* loading done */ });
moment.locale(locale_example);

oh = new opening_hours('Montag und Dienstag', nominatiomTestJSON, { 'tag_key': 'opening_hours', 'locale': 'de'});
console.log(oh.getWarnings());

Attachments (2)

11755.patch (555.0 KB ) - added by simon04 9 years ago.
11755b.patch (555.1 KB ) - added by simon04 9 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 by bastiK, 9 years ago

Milestone: 15.07

comment:2 by Klumbumbus, 9 years ago

Currently it is translated via launchpad, right? What was the reason to change this?

comment:3 by ypid23, 9 years ago

No. Before v3.3.0 only some warnings where localized because it was clear from the problem which language was used. Like someone using "Donnerstag" instead of Th. Now amenk has submitted a patch (see https://github.com/ypid/opening_hours.js/issues/89) which translates error messages as well. Translations can be added to https://github.com/ypid/opening_hours.js/tree/master/locales

comment:4 by Don-vip, 9 years ago

How do we include the new languages? Is it enough to update the opening_hours.js file, or do we need to include this new core.js file as well? If yes, in a specific subdirectory?

comment:5 by Don-vip, 9 years ago

Milestone: 15.0715.08

Milestone renamed

in reply to:  3 comment:6 by Klumbumbus, 9 years ago

Replying to ypid23:

No. ... Translations can be added to https://github.com/ypid/opening_hours.js/tree/master/locales

OK, I didn't know that. German is translated 100%?

comment:7 by ypid23, 9 years ago

Unfortunately, you have to add more than those two files. You would have to add the libraries moment and i18next as well and globally define them as shown in the example. I am not quite sure how to do this in the JavaScript implementation you are using for Java.
Subdirectory does not matter as long as you adopt the source code example I posted above. It is all added to run time variables in JavaScript. No file open stuff inside of the library.

All errors are translated to German. There are some warnings which are currently not. For example, if you use the opening_hours "Friday" it will not translate the warning message (yet).

comment:8 by Don-vip, 9 years ago

Mmm this is not easy. Does anyone have any experience with running NodeJS modules in the JVM? I face difficulties with the require directives.

comment:9 by Don-vip, 9 years ago

Keywords: javascript nodejs module require rhino nashorn java7 java8 added

comment:10 by simon04, 9 years ago

Browserify allows to resolve dependencies and builds a single file for browser usage. I got the 3.3 version to work w/ this approach:

  • src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java

    diff --git a/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java b/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
    index 91c2502..2a8373c 100644
    a b public void initialize() throws Exception {  
    5455            try (Reader reader = new InputStreamReader(
    5556                    new CachedFile("resource://data/validator/opening_hours.js").getInputStream(), StandardCharsets.UTF_8)) {
    5657                ENGINE.eval(reader);
     58                ENGINE.eval("var opening_hours = require('opening_hours');");
    5759                // fake country/state to not get errors on holidays
    5860                ENGINE.eval("var nominatimJSON = {address: {state: 'Bayern', country_code: 'de'}};");
    5961                ENGINE.eval(

See also https://github.com/ypid/opening_hours.js/pull/96

However, the I18n part is to be done …

by simon04, 9 years ago

Attachment: 11755.patch added

comment:11 by simon04, 9 years ago

Milestone: 15.0815.09

A patch (attachment:11755.patch) with the modifications from https://github.com/ypid/opening_hours.js/pull/98 included. The tests pass, but nevertheless I would keep it for the next release …

comment:12 by Don-vip, 9 years ago

ok :) thanks for the tip!

by simon04, 9 years ago

Attachment: 11755b.patch added

comment:13 by simon04, 9 years ago

https://github.com/ypid/opening_hours.js/pull/98 has been applied with minor modifications. attachment:11755b.patch is the correspondingly updated patch. The javascript file has been generated using make opening_hours+deps.min.js in the opening_hours.js project.

Last edited 9 years ago by simon04 (previous) (diff)

comment:14 by simon04, 9 years ago

Owner: changed from team to simon04

comment:15 by simon04, 9 years ago

Resolution: fixed
Status: newclosed

In 8680/josm:

fix #11755 - Update version of opening_hours.js to 3.3.0

comment:16 by Don-vip, 8 years ago

In 10550/josm:

see #11755, see #13145 - update version of opening_hours.js to 3.4.0

comment:17 by Don-vip, 8 years ago

In 11595/josm:

see #11755, see #14381 - Update version of opening_hours.js to 3.5.0

Generated using npm install browserify moment i18next-client country-language suncalc && make opening_hours+deps.min.js

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain simon04.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.