rotor-framework 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +120 -0
- package/package.json +59 -0
- package/src/source/RotorFramework.bs +654 -0
- package/src/source/RotorFrameworkTask.bs +278 -0
- package/src/source/base/BaseModel.bs +52 -0
- package/src/source/base/BasePlugin.bs +48 -0
- package/src/source/base/BaseReducer.bs +184 -0
- package/src/source/base/BaseStack.bs +92 -0
- package/src/source/base/BaseViewModel.bs +124 -0
- package/src/source/base/BaseWidget.bs +104 -0
- package/src/source/base/DispatcherCreator.bs +193 -0
- package/src/source/base/DispatcherExternal.bs +260 -0
- package/src/source/base/ListenerForDispatchers.bs +246 -0
- package/src/source/engine/Constants.bs +74 -0
- package/src/source/engine/animator/Animator.bs +334 -0
- package/src/source/engine/builder/Builder.bs +213 -0
- package/src/source/engine/builder/NodePool.bs +236 -0
- package/src/source/engine/builder/PluginAdapter.bs +139 -0
- package/src/source/engine/builder/PostProcessor.bs +331 -0
- package/src/source/engine/builder/Processor.bs +156 -0
- package/src/source/engine/builder/Tree.bs +278 -0
- package/src/source/engine/builder/TreeBase.bs +313 -0
- package/src/source/engine/builder/WidgetCreate.bs +322 -0
- package/src/source/engine/builder/WidgetRemove.bs +72 -0
- package/src/source/engine/builder/WidgetUpdate.bs +113 -0
- package/src/source/engine/providers/Dispatcher.bs +72 -0
- package/src/source/engine/providers/DispatcherProvider.bs +95 -0
- package/src/source/engine/services/I18n.bs +169 -0
- package/src/source/libs/animate/Animate.bs +753 -0
- package/src/source/libs/animate/LICENSE.txt +21 -0
- package/src/source/plugins/DispatcherProviderPlugin.bs +127 -0
- package/src/source/plugins/FieldsPlugin.bs +180 -0
- package/src/source/plugins/FocusPlugin.bs +1522 -0
- package/src/source/plugins/FontStylePlugin.bs +159 -0
- package/src/source/plugins/ObserverPlugin.bs +548 -0
- package/src/source/utils/ArrayUtils.bs +495 -0
- package/src/source/utils/GeneralUtils.bs +181 -0
- package/src/source/utils/NodeUtils.bs +180 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
' ===== I18N SERVICE =====
|
|
2
|
+
namespace Rotor.ViewBuilder
|
|
3
|
+
|
|
4
|
+
' =====================================================================
|
|
5
|
+
' I18nService - Internationalization service for managing locales and localized content
|
|
6
|
+
'
|
|
7
|
+
' Provides l10n (localization) data access, RTL detection, and caching.
|
|
8
|
+
'
|
|
9
|
+
' @future Implement more static data and expressions like dateFormat, timeFormat,
|
|
10
|
+
' currencySymbol, decimalSeparator, thousandsSeparator.
|
|
11
|
+
' Examples: getDecimalSeparator(), getThousandSeparator(),
|
|
12
|
+
' getCurrencyCode(), getPluralCategory(count)
|
|
13
|
+
' =====================================================================
|
|
14
|
+
class I18nService
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
l10n = {}
|
|
18
|
+
cache = {}
|
|
19
|
+
locale as string
|
|
20
|
+
isRTL = false
|
|
21
|
+
frameworkInstance as Rotor.Framework
|
|
22
|
+
|
|
23
|
+
' RTL language codes
|
|
24
|
+
RTL_LANGUAGES = ["ar", "he", "fa", "ur"]
|
|
25
|
+
|
|
26
|
+
' ---------------------------------------------------------------------
|
|
27
|
+
' init - Initializes the i18n service with default locale
|
|
28
|
+
'
|
|
29
|
+
' @param {Rotor.Framework} frameworkInstance - Framework instance reference
|
|
30
|
+
'
|
|
31
|
+
sub init(frameworkInstance as Rotor.Framework)
|
|
32
|
+
m.locale = "en_US"
|
|
33
|
+
m.isRTL = m.detectRTL(m.locale)
|
|
34
|
+
' m.locale = frameworkInstance.getInfo().device.currentLocale
|
|
35
|
+
' m.frameworkInstance = frameworkInstance
|
|
36
|
+
end sub
|
|
37
|
+
|
|
38
|
+
' ---------------------------------------------------------------------
|
|
39
|
+
' setLocal - Sets the current locale and updates RTL flag
|
|
40
|
+
'
|
|
41
|
+
' @param {string} locale - Locale string (e.g., "en_US", "ar_SA")
|
|
42
|
+
'
|
|
43
|
+
sub setLocal(locale as string)
|
|
44
|
+
m.locale = locale
|
|
45
|
+
m.isRTL = m.detectRTL(locale)
|
|
46
|
+
end sub
|
|
47
|
+
|
|
48
|
+
' ---------------------------------------------------------------------
|
|
49
|
+
' getLocale - Gets the current locale string
|
|
50
|
+
'
|
|
51
|
+
' @returns {string} Current locale (e.g., "en_US")
|
|
52
|
+
'
|
|
53
|
+
function getLocale() as string
|
|
54
|
+
return m.locale
|
|
55
|
+
end function
|
|
56
|
+
|
|
57
|
+
' ---------------------------------------------------------------------
|
|
58
|
+
' detectRTL - Detects if locale uses RTL (Right-to-Left) direction
|
|
59
|
+
'
|
|
60
|
+
' @param {string} locale - Locale string to check
|
|
61
|
+
' @returns {boolean} True if locale is RTL, false otherwise
|
|
62
|
+
' @private
|
|
63
|
+
'
|
|
64
|
+
private function detectRTL(locale as string) as boolean
|
|
65
|
+
if locale = invalid or locale = "" then return false
|
|
66
|
+
|
|
67
|
+
' Extract language code (e.g., "ar_SA" -> "ar")
|
|
68
|
+
languageCode = locale.Split("_")[0]
|
|
69
|
+
|
|
70
|
+
' Check if language is in RTL list
|
|
71
|
+
for each rtlLang in m.RTL_LANGUAGES
|
|
72
|
+
if languageCode = rtlLang then return true
|
|
73
|
+
end for
|
|
74
|
+
|
|
75
|
+
return false
|
|
76
|
+
end function
|
|
77
|
+
|
|
78
|
+
' ---------------------------------------------------------------------
|
|
79
|
+
' setL10n - Sets the localization data and refreshes cache
|
|
80
|
+
'
|
|
81
|
+
' @param {object} l10n - Localization data object
|
|
82
|
+
'
|
|
83
|
+
sub setL10n(l10n as object)
|
|
84
|
+
m.l10n = l10n
|
|
85
|
+
m.refreshCache()
|
|
86
|
+
end sub
|
|
87
|
+
|
|
88
|
+
' ---------------------------------------------------------------------
|
|
89
|
+
' extendL10n - Extends the existing localization data and refreshes cache
|
|
90
|
+
'
|
|
91
|
+
' @param {object} l10n - Localization data to merge
|
|
92
|
+
'
|
|
93
|
+
sub extendL10n(l10n as object)
|
|
94
|
+
Rotor.Utils.deepExtendAA(m.l10n, l10n)
|
|
95
|
+
m.refreshCache()
|
|
96
|
+
end sub
|
|
97
|
+
|
|
98
|
+
' ---------------------------------------------------------------------
|
|
99
|
+
' destroy - Cleans up cache and l10n data
|
|
100
|
+
'
|
|
101
|
+
sub destroy()
|
|
102
|
+
' m.frameworkInstance = invalid
|
|
103
|
+
m.cache.Clear()
|
|
104
|
+
m.l10n.Clear()
|
|
105
|
+
end sub
|
|
106
|
+
|
|
107
|
+
' ---------------------------------------------------------------------
|
|
108
|
+
' refreshCache - Refreshes the l10n cache by re-cloning all cached key paths
|
|
109
|
+
'
|
|
110
|
+
' @private
|
|
111
|
+
'
|
|
112
|
+
sub refreshCache()
|
|
113
|
+
m.cache.Clear()
|
|
114
|
+
for each cacheKey in m.cache
|
|
115
|
+
m.cache[cacheKey] = Rotor.Utils.getCloneByKeyPath(m.l10n, cacheKey)
|
|
116
|
+
end for
|
|
117
|
+
end sub
|
|
118
|
+
|
|
119
|
+
' ---------------------------------------------------------------------
|
|
120
|
+
' getIsRtl - Gets whether current locale is RTL
|
|
121
|
+
'
|
|
122
|
+
' @returns {boolean} True if current locale is RTL
|
|
123
|
+
'
|
|
124
|
+
public function getIsRtl() as boolean
|
|
125
|
+
return m.isRTL
|
|
126
|
+
end function
|
|
127
|
+
|
|
128
|
+
' ---------------------------------------------------------------------
|
|
129
|
+
' getL10n - Gets localization data by key path or entire l10n object
|
|
130
|
+
'
|
|
131
|
+
' @param {dynamic} keyPath - Key path string or invalid for entire l10n
|
|
132
|
+
' @returns {object} Localization data (reference if invalid, cloned if keyPath provided)
|
|
133
|
+
'
|
|
134
|
+
public function getL10n(keyPath) as object
|
|
135
|
+
' Best for regular use cases
|
|
136
|
+
if keyPath = invalid then return m.l10n ' Return just reference to l10n
|
|
137
|
+
|
|
138
|
+
' Best for unit tests or story books or special use cases
|
|
139
|
+
firstKey = keyPath.Split(".")[0]
|
|
140
|
+
return m.getAssetByKeyPath(keyPath)[firstKey] ' Return cloned and merged sliced data from l10n
|
|
141
|
+
|
|
142
|
+
end function
|
|
143
|
+
|
|
144
|
+
' ---------------------------------------------------------------------
|
|
145
|
+
' getAssetByKeyPath - Gets and caches localization data by one or more key paths
|
|
146
|
+
'
|
|
147
|
+
' @param {dynamic} keyPath - Single key path string or array of key paths
|
|
148
|
+
' @returns {object} Merged localization data from all key paths
|
|
149
|
+
' @private
|
|
150
|
+
'
|
|
151
|
+
function getAssetByKeyPath(keyPath as dynamic) as object
|
|
152
|
+
keysPaths = Rotor.Utils.ensureArray(keyPath)
|
|
153
|
+
asset = {}
|
|
154
|
+
for each keyPath in keysPaths
|
|
155
|
+
if m.cache.DoesExist(keyPath)
|
|
156
|
+
additionalAsset = m.cache[keyPath]
|
|
157
|
+
else
|
|
158
|
+
additionalAsset = Rotor.Utils.getCloneByKeyPath(m.l10n, keyPath) ' TODO: reconsider to use getValueByKeyPath instead
|
|
159
|
+
m.cache[keyPath] = additionalAsset
|
|
160
|
+
end if
|
|
161
|
+
Rotor.Utils.deepExtendAA(asset, additionalAsset)
|
|
162
|
+
end for
|
|
163
|
+
return asset
|
|
164
|
+
end function
|
|
165
|
+
|
|
166
|
+
end class
|
|
167
|
+
|
|
168
|
+
end namespace
|
|
169
|
+
|