#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)
Change History (19)
comment:1 by , 9 years ago
Milestone: | → 15.07 |
---|
comment:2 by , 9 years ago
follow-up: 6 comment:3 by , 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 , 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:6 by , 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 , 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 , 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 , 9 years ago
Keywords: | javascript nodejs module require rhino nashorn java7 java8 added |
---|
comment:10 by , 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 { 54 55 try (Reader reader = new InputStreamReader( 55 56 new CachedFile("resource://data/validator/opening_hours.js").getInputStream(), StandardCharsets.UTF_8)) { 56 57 ENGINE.eval(reader); 58 ENGINE.eval("var opening_hours = require('opening_hours');"); 57 59 // fake country/state to not get errors on holidays 58 60 ENGINE.eval("var nominatimJSON = {address: {state: 'Bayern', country_code: 'de'}};"); 59 61 ENGINE.eval(
See also https://github.com/ypid/opening_hours.js/pull/96
However, the I18n part is to be done …
by , 9 years ago
Attachment: | 11755.patch added |
---|
comment:11 by , 9 years ago
Milestone: | 15.08 → 15.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 …
by , 9 years ago
Attachment: | 11755b.patch added |
---|
comment:13 by , 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.
comment:14 by , 9 years ago
Owner: | changed from | to
---|
Currently it is translated via launchpad, right? What was the reason to change this?