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

Allow localization of b.weekday() #113

Open
trych opened this issue Oct 24, 2016 · 12 comments
Open

Allow localization of b.weekday() #113

trych opened this issue Oct 24, 2016 · 12 comments
Assignees

Comments

@trych
Copy link
Contributor

trych commented Oct 24, 2016

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
Copy link
Member

ff6347 commented Oct 24, 2016

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

@trych
Copy link
Contributor Author

trych commented Oct 24, 2016

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
Copy link
Member

b-g commented Oct 25, 2016

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
Copy link
Member

ff6347 commented Oct 25, 2016

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
Copy link
Member

ff6347 commented Oct 25, 2016

But this still gives me the german locale. 😞

$.locale = 'ru';
var d = new Date();
$.writeln(d.toLocaleString());
$.locale = null;

@trych
Copy link
Contributor Author

trych commented Oct 25, 2016

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
Copy link
Member

b-g commented Oct 25, 2016

Ok, never mind. Then leave it in place.

@ff6347
Copy link
Member

ff6347 commented Oct 26, 2016

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
Copy link
Member

b-g commented Oct 26, 2016

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

@ff6347
Copy link
Member

ff6347 commented Oct 26, 2016

Can do.

@trych
Copy link
Contributor Author

trych commented Oct 26, 2016

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
Copy link
Member

ff6347 commented Oct 27, 2016

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.

@ff6347 ff6347 self-assigned this Nov 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants