basiljs / basil.js

An attempt to port the spirit of the Processing visualization language to Adobe Indesign.
http://basiljs.ch/
Other
245 stars 30 forks source link

Allow localization of b.weekday() #113

Open trych opened 7 years ago

trych commented 7 years ago

This one is simple, just allow an optional array argument for b.weekday() that contains localized names.

I am under the impression that most basil users at the moment are German speaking. And while I agree that the primary language should remain English of course, it would be nice to allow the localization of this. As far as I am aware this is the only localized string in the entire library?

Usage: b.weekday( ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"] );

ff6347 commented 7 years ago

What about using localization codes instead? http://stackoverflow.com/questions/10763761/getting-localized-day-of-week

trych commented 7 years ago

Interesting, I had no idea you could do that.

But I don't think that is the best solution in this case. Maybe the user makes a design where he requires English names (or German ones, Spanish ones etc.) and then the script would not reliably produce the desired result on different systems.

Allowing an optional localization array is the easiest way I can think of to achieve that.

b-g commented 7 years ago

Should we rather not get rid of this special case? I doubt that anyone is using it, even I've never heard about it. @ffd8 could we kill this?

ff6347 commented 7 years ago

I took a look into the Javascript Tools guide.pdf (You can find it under Help in the ESTK ). There is already a localization feature build in to Extendscript. This for example sets the locale tu russian.

$.locale = 'ru';
var CANCEL = { en: 'FOO', de: 'BAH', ru:'BAZ'};
$.writeln(localize(CANCEL));
$.locale = null;

The guide says you should set it back to null to restore the default system locale. Might be helpful.

ff6347 commented 7 years ago

But this still gives me the german locale. 😞

$.locale = 'ru';
var d = new Date();
$.writeln(d.toLocaleString());
$.locale = null;
trych commented 7 years ago

Should we rather not get rid of this special case? I doubt that anyone is using it, even I've never heard about it.

What do you mean, the function itself? I used it in the past quite a bit and some people in my course have used it already. So, even for backwards compatibility, I would not take it out. I just thought that the possibility to customize it with your own array improves the usability.

b-g commented 7 years ago

Ok, never mind. Then leave it in place.

ff6347 commented 7 years ago

I still think it is nice to have some localisation feature for the days. We could build on this:

    /**
     * supported codes are currently
     * en (default), de, es, it
     *
     */
    pub.weekdays = function(CCODE) {
      var res = null;
      var dt = new Date();
      var day = dt.getDay();
      var splitter = function(str, i) {
        return str.split('|')[i];
      };
      var days = {
        en: 'Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday',
        de: 'Sonntag|Montag|Dienstag|Mittwoch|Donnerstag|Freitag|Samstag',
        es: 'domingo|lunes|martes|miércoles|jueves|viernes|sábado',
        it: 'domenica|lunedì|martedì|mercoledì|giovedì|venerdì|sabato'

      };
      if(arguments.length > 0) {

        if(days.hasOwnProperty(CCODE) === true) {
          $.locale = CCODE;
          var locale_days = localize(days);
          res = splitter(locale_days, day);
          $.locale = null;
        } else {
          res = splitter(days.en, day);
        }
      }else{
        res = splitter(days.en, day);
      }
      return res;
    };

    weekdays('es');

Just for the fun of it. 😸 Then we look for a list like this one http://www.omniglot.com/language/time/days.htm

b-g commented 7 years ago

ok + nice! @fabianmoronzirfas, can you reference/document in the wiki then the "basil localisation pattern" ...

ff6347 commented 7 years ago

Can do.

trych commented 7 years ago

So that means we copy ALL InDesign localization strings into the source code? Would it not still be better to allow for customization, if – let's say – I want to have icelandic weekdays? Or what's the idea here?

ff6347 commented 7 years ago

No. I would not do that. Just weekdays. It's just fun and low priority. But we could allow the user to paste in a "Basil-day-format" string and the lib parses it and gets the right day.