sproutcore / deprecated / string.js
100644 110 lines (90 sloc) 3.237 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// ==========================================================================
// SproutCore -- JavaScript Application Framework
// Copyright ©2006-2008, Sprout Systems, Inc. and contributors.
// Portions Copyright ©2008 Apple, Inc. All rights reserved..
// ==========================================================================
 
require('mixins/string');
 
// deprecated, mostly useless API, that was blindly copied from Prototype
SC.mixin(String.prototype, {
    
    /** @deprecated
Explodes a string into an array of characters.
 
@returns {Array}
*/
    toArray: function() {
      return this.split('');
    },
    
    // Deprecated, longer version of this method.
    format: SC.String.fmt
});
 
// Add strings for various languages to this collection. String.loc()
// method will try to localize the string passed using the current language.
// if the language is not available, it will use English.
SC.mixin(String,
/** @scope String @static */ {
 
  /** @deprecated
The current browser language as a two letter code.
Use SC.browser.language instead.
*/
  browserLanguage: ((navigator.language || navigator.browserLanguage).split('-', 1)[0]),
  
  /** @deprecated
If YES, localization will favor the detected language instead of the
preferred one.
Use SC.Locale.useAutodetectedLanguage instead.
*/
  useAutodetectedLanguage: null,
  
  /** @deprecated
This property is set by the build tools to the current build language.
Use SC.Locale.preferredLanguage instead
*/
  preferredLanguage: null,
  
  /** @deprecated
Returns the hash key to use for loc strings. The default implementation
will autodetect the browser language and look for a loc string to
match. If it can't find one then it will introspect to find loc strings
that are defined and use those instead.
Use SC.Locale.currentLanguage property instead.
*/
  currentLanguage: function () {
    return this.normalizedLanguage(SC.Locale.currentLanguage);
  },
  
  /** @deprecated
Returns a normalized language string for the two letter country code.
Use SC.Locale.normalizeLanguage() instead.
*/
  normalizedLanguage: function(ret) {
    switch(SC.Locale.normalizeLanguage(ret).split('-')[0]) {
      case 'en':
        ret = 'English' ;
        break;
      case 'fr':
        ret = 'French' ;
        break ;
      case 'ja':
        ret = 'Japanese' ;
        break ;
      case 'de':
        ret = 'German' ;
        break ;
      case 'es':
        ret = 'Spanish' ;
        break;
      default:
        ret = 'English';
    }
    return ret ;
  },
  
  /**
Adds loc strings for the named language. This method takes care of
creating the localized string hash if it does not already exist.
The language can be one of the following or any two-letter country code.
English, French, German, Japanese, Spanish
@param language {String} the language code
@param strings {Hash} hash of loc strings.
@returns {this}
*/
  addStringsFor: SC.stringsFor
 
});
 
String.English = String.English || {};
String.French = String.French || {};
String.German = String.German || {};
String.Japanese = String.Japanese || {};