1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { paramMock } from "../utils" 17 18export function mockIntl() { 19 const result = { 20 DateTimeFormat: function (...args) { 21 console.warn("Intl.DateTimeFormat interface mocked in the Previewer. How this interface works on the Previewer" + 22 " may be different from that on a real device.") 23 return DateTimeFormatMock; 24 }, 25 NumberFormat: function (...args) { 26 console.warn("Intl.NumberFormat interface mocked in the Previewer. How this interface works on the Previewer" + 27 " may be different from that on a real device.") 28 return NumberFormatMock; 29 }, 30 Locale: function (locale) { 31 console.warn("Intl.Locale interface mocked in the Previewer. How this interface works on the Previewer" + 32 " may be different from that on a real device.") 33 return LocaleMock; 34 }, 35 Collator: function (...args) { 36 console.warn("Intl.Collator interface mocked in the Previewer. How this interface works on the Previewer" + 37 " may be different from that on a real device.") 38 return CollatorMock; 39 }, 40 PluralRules: function (...args) { 41 console.warn("Intl.PluralRules interface mocked in the Previewer. How this interface works on the Previewer" + 42 " may be different from that on a real device.") 43 return PluralRulesMock; 44 }, 45 RelativeTimeFormat: function (...args) { 46 console.warn("Intl.RelativeTimeFormat interface mocked in the Previewer. How this interface works on the Previewer" + 47 " may be different from that on a real device.") 48 return RelativeTimeFormatMock; 49 } 50 } 51 const DateTimeFormatMock = { 52 format: function (date) { 53 console.warn("Intl.DateTimeFormat.format interface mocked in the Previewer. How this interface works on the" + 54 " Previewer may be different from that on a real device."); 55 return paramMock.paramStringMock; 56 }, 57 formatRange: function (startDate, endDate) { 58 console.warn("Intl.DateTimeFormat.format interface mocked in the Previewer. How this interface works on the" + 59 " Previewer may be different from that on a real device."); 60 return paramMock.paramStringMock; 61 }, 62 resolvedOptions: function () { 63 console.warn("Intl.DateTimeFormat.resolvedOptions interface mocked in the Previewer. How this interface works on the" + 64 " Previewer may be different from that on a real device."); 65 return DateTimeOptionsMock; 66 } 67 } 68 const NumberFormatMock = { 69 format: function (number) { 70 console.warn("Intl.NumberFormat.format interface mocked in the Previewer. How this interface works on the" + 71 " Previewer may be different from that on a real device."); 72 return paramMock.paramStringMock; 73 }, 74 resolvedOptions: function () { 75 console.warn("Intl.NumberFormat.resolvedOptions interface mocked in the Previewer. How this interface works on the" + 76 " Previewer may be different from that on a real device."); 77 return NumberOptionsMock; 78 } 79 } 80 const LocaleMock = { 81 language: '[PC preview] unknow language', 82 script: '[PC preview] unknow script', 83 region: '[PC preview] unknow region', 84 baseName: '[PC preview] unknow baseName', 85 caseFirst: '[PC preview] unknow caseFirst', 86 calendar: '[PC preview] unknow calendar', 87 collation: '[PC preview] unknow collation', 88 hourCycle: '[PC preview] unknow hourCycle', 89 numberingSystem: '[PC preview] unknow numberingSystem', 90 numeric: '[PC preview] unknow numeric', 91 toString: function () { 92 console.warn("Intl.Locale.toString interface mocked in the Previewer. How this interface works on the" + 93 " Previewer may be different from that on a real device."); 94 return paramMock.paramStringMock; 95 }, 96 maximize: function () { 97 console.warn("Intl.Locale.maximize interface mocked in the Previewer. How this interface works on the" + 98 " Previewer may be different from that on a real device."); 99 return LocaleMock; 100 }, 101 minimize: function () { 102 console.warn("Intl.Locale.minimize interface mocked in the Previewer. How this interface works on the" + 103 " Previewer may be different from that on a real device."); 104 return LocaleMock; 105 } 106 } 107 const CollatorMock = { 108 compare: function (firstString, secondString) { 109 console.warn("Intl.Collator.compare interface mocked in the Previewer. How this interface works on the" + 110 " Previewer may be different from that on a real device."); 111 return paramMock.paramNumberMock; 112 }, 113 resolvedOptions: function () { 114 console.warn("Intl.Collator.resolvedOptions interface mocked in the Previewer. How this interface works on the" + 115 " Previewer may be different from that on a real device."); 116 return CollatorOptionsMock; 117 } 118 } 119 const PluralRulesMock = { 120 select: function (number) { 121 console.warn("Intl.PluralRules.select interface mocked in the Previewer. How this interface works on the" + 122 " Previewer may be different from that on a real device."); 123 return paramMock.paramStringMock; 124 } 125 } 126 const RelativeTimeFormatMock = { 127 format: function (value, unit) { 128 console.warn("Intl.RelativeTimeFormat.format interface mocked in the Previewer. How this interface works on the" + 129 " Previewer may be different from that on a real device."); 130 return paramMock.paramStringMock; 131 }, 132 formatToParts: function (value, unit) { 133 console.warn("Intl.RelativeTimeFormat.formatToParts interface mocked in the Previewer. How this interface works on the" + 134 " Previewer may be different from that on a real device."); 135 return paramMock.paramArrayMock; 136 }, 137 resolvedOptions: function () { 138 console.warn("Intl.RelativeTimeFormat.resolvedOptions interface mocked in the Previewer. How this interface works on the" + 139 " Previewer may be different from that on a real device."); 140 return RelativeTimeFormatResolvedOptionsMock; 141 } 142 } 143 const DateTimeOptionsMock = { 144 locale: '[PC preview] unknow locale', 145 dateStyle: '[PC preview] unknow dateStyle', 146 timeStyle: '[PC preview] unknow timeStyle', 147 hourCycle: '[PC preview] unknow hourCycle', 148 timeZone: '[PC preview] unknow timeZone', 149 numberingSystem: '[PC preview] unknow numberingSystem', 150 hour12: '[PC preview] unknow hour12', 151 weekday: '[PC preview] unknow weekday', 152 era: '[PC preview] unknow era', 153 year: '[PC preview] unknow year', 154 month: '[PC preview] unknow month', 155 day: '[PC preview] unknow day', 156 hour: '[PC preview] unknow hour', 157 minute: '[PC preview] unknow minute', 158 second: '[PC preview] unknow second', 159 timeZoneName: '[PC preview] unknow timeZoneName', 160 dayPeriod: '[PC preview] unknow dayPeriod', 161 localeMatcher: '[PC preview] unknow localeMatcher', 162 formatMatcher: '[PC preview] unknow formatMatcher', 163 } 164 const NumberOptionsMock = { 165 locale: '[PC preview] unknow locale', 166 currency: '[PC preview] unknow currency', 167 currencySign: '[PC preview] unknow currencySign', 168 currencyDisplay: '[PC preview] unknow currencyDisplay', 169 unit: '[PC preview] unknow unit', 170 unitDisplay: '[PC preview] unknow unitDisplay', 171 unitUsage: '[PC preview] unknow unitUsage', 172 signDisplay: '[PC preview] unknow signDisplay', 173 compactDisplay: '[PC preview] unknow compactDisplay', 174 notation: '[PC preview] unknow notation', 175 localeMatcher: '[PC preview] unknow localeMatcher', 176 style: '[PC preview] unknow style', 177 numberingSystem: '[PC preview] unknow numberingSystem', 178 useGrouping: '[PC preview] unknow useGrouping', 179 minimumIntegerDigits: '[PC preview] unknow minimumIntegerDigits', 180 minimumFractionDigits: '[PC preview] unknow minimumFractionDigits', 181 maximumFractionDigits: '[PC preview] unknow maximumFractionDigits', 182 minimumSignificantDigits: '[PC preview] unknow minimumSignificantDigits', 183 maximumSignificantDigits: '[PC preview] unknow maximumSignificantDigits', 184 } 185 const CollatorOptionsMock = { 186 localeMatcher: '[PC preview] unknow localeMatcher', 187 usage: '[PC preview] unknow usage', 188 sensitivity: '[PC preview] unknow sensitivity', 189 ignorePunctuation: '[PC preview] unknow ignorePunctuation', 190 collation: '[PC preview] unknow collation', 191 numeric: '[PC preview] unknow numeric', 192 caseFirst: '[PC preview] unknow caseFirst', 193 } 194 const PluralRulesOptionsMock = { 195 localeMatcher: '[PC preview] unknow localeMatcher', 196 type: '[PC preview] unknow type', 197 minimumIntegerDigits: '[PC preview] unknow minimumIntegerDigits', 198 minimumFractionDigits: '[PC preview] unknow minimumFractionDigits', 199 maximumFractionDigits: '[PC preview] unknow maximumFractionDigits', 200 minimumSignificantDigits: '[PC preview] unknow minimumSignificantDigits', 201 maximumSignificantDigits: '[PC preview] unknow maximumSignificantDigits', 202 } 203 const RelativeTimeFormatResolvedOptions = { 204 locale: '[PC preview] unknow locale', 205 style: '[PC preview] unknow style', 206 numeric: '[PC preview] unknow numeric', 207 numberingSystem: '[PC preview] unknow numberingSystem', 208 } 209 const RelativeTimeFormatInputOptions = { 210 localeMatcher: '[PC preview] unknow localeMatcher', 211 numeric: '[PC preview] unknow numeric', 212 style: '[PC preview] unknow style', 213 } 214 const LocaleOptions = { 215 calendar: '[PC preview] unknow calendar', 216 collation: '[PC preview] unknow collation', 217 hourCycle: '[PC preview] unknow hourCycle', 218 numberingSystem: '[PC preview] unknow numberingSystem', 219 numeric: '[PC preview] unknow numeric', 220 caseFirst: '[PC preview] unknow caseFirst', 221 } 222 return result; 223}