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 16/** 17 * Provides international settings related APIs. 18 * 19 * @syscap SystemCapability.Global.I18n 20 * @since 7 21 */ 22declare namespace i18n { 23/** 24 * Obtains the country or region name localized for display on a given locale. 25 * 26 * @syscap SystemCapability.Global.I18n 27 * @param country The locale whose country or region name will be displayed. 28 * @param locale The locale used to display the country or region. 29 * @param sentenceCase Specifies whether the country or region name is displayed in sentence case. 30 * @return Returns the country or region name localized for display on a given locale. 31 * @since 7 32 */ 33export function getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string; 34 35/** 36 * Obtains the language name localized for display on a given locale. 37 * 38 * @syscap SystemCapability.Global.I18n 39 * @param language The locale whose language name will be displayed. 40 * @param locale The locale used to display the language. 41 * @param sentenceCase Specifies whether the language name is displayed in sentence case. 42 * @return Returns the language name localized for display on a given locale. 43 * @since 7 44 */ 45export function getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string; 46 47/** 48 * Obtain all languages supported by the system. 49 * 50 * @syscap SystemCapability.Global.I18n 51 * @return Returns all languages supported by the system. 52 * @since 7 53 * @systemapi Hide this for inner system use. 54 */ 55export function getSystemLanguages(): Array<string>; 56 57/** 58 * Obtain all regions supported by the system in the language. 59 * 60 * @syscap SystemCapability.Global.I18n 61 * @param language The language used to get the list of regions. 62 * @return Returns all regions supported by the system in the language. 63 * @since 7 64 * @systemapi Hide this for inner system use. 65 */ 66export function getSystemCountries(language: string): Array<string>; 67 68/** 69 * Determine whether the current language or region is recommended. 70 * 71 * @syscap SystemCapability.Global.I18n 72 * @param language The language code. 73 * @param region The region code. 74 * @return Returns whether the current language or region is recommended. 75 * @since 7 76 * @systemapi Hide this for inner system use. 77 */ 78export function isSuggested(language: string, region?: string): boolean; 79 80/** 81 * Obtain the language currently used by the system. 82 * 83 * @syscap SystemCapability.Global.I18n 84 * @return Returns the language currently used by the system. 85 * @since 7 86 */ 87export function getSystemLanguage(): string; 88 89/** 90 * Set the language currently used by the system. 91 * 92 * @permission ohos.permission.UPDATE_CONFIGURATION 93 * @syscap SystemCapability.Global.I18n 94 * @param language The language to be used. 95 * @since 7 96 * @systemapi Hide this for inner system use. 97 */ 98export function setSystemLanguage(language: string): boolean; 99 100/** 101 * Obtain the region currently used by the system. 102 * 103 * @syscap SystemCapability.Global.I18n 104 * @return Returns the region currently used by the system. 105 * @since 7 106 */ 107export function getSystemRegion(): string; 108 109/** 110 * Set the region currently used by the system. 111 * 112 * @permission ohos.permission.UPDATE_CONFIGURATION 113 * @syscap SystemCapability.Global.I18n 114 * @param region The region to be used. 115 * @since 7 116 * @systemapi Hide this for inner system use. 117 */ 118export function setSystemRegion(region: string): boolean; 119 120/** 121 * Obtain the locale currently used by the system. 122 * 123 * @syscap SystemCapability.Global.I18n 124 * @return Returns the locale currently used by the system. 125 * @since 7 126 */ 127export function getSystemLocale(): string; 128 129/** 130 * Set the locale currently used by the system. 131 * 132 * @permission ohos.permission.UPDATE_CONFIGURATION 133 * @syscap SystemCapability.Global.I18n 134 * @param locale The locale to be used. 135 * @since 7 136 * @systemapi Hide this for inner system use. 137 */ 138export function setSystemLocale(locale: string): boolean; 139 140/** 141 * Provides util functions. 142 * 143 * @syscap SystemCapability.Global.I18n 144 * @since 8 145 */ 146export interface Util { 147 /** 148 * Convert from unit to to unit and format according to the locale. 149 * 150 * @syscap SystemCapability.Global.I18n 151 * @param fromUnit Information of the unit to be converted. 152 * @param toUnit Information about the unit to be converted to. 153 * @param value Indicates the number to be formatted. 154 * @param locale The locale to be used. 155 * @param style The style of format. 156 * @since 8 157 */ 158 unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string; 159} 160 161/** 162 * Provides the options of unit. 163 * 164 * @syscap SystemCapability.Global.I18n 165 * @since 8 166 */ 167export interface UnitInfo { 168 /** 169 * Unit name. 170 */ 171 unit: string 172 173 /** 174 * The measurement system of the unit. 175 */ 176 measureSystem: string 177} 178 179/** 180 * Provides the options of PhoneNumberFormat. 181 * 182 * @syscap SystemCapability.Global.I18n 183 * @since 8 184 */ 185export interface PhoneNumberFormatOptions { 186 /** 187 * Indicates the type to format phone number. 188 */ 189 type: string; 190} 191 192/** 193 * Provides the API for formatting phone number strings 194 * 195 * @syscap SystemCapability.Global.I18n 196 * @since 8 197 */ 198export class PhoneNumberFormat { 199 /** 200 * A constructor used to create a PhoneNumberFormat object. 201 * 202 * @syscap SystemCapability.Global.I18n 203 * @param country Indicates a character string containing the country information for the PhoneNumberFormat object. 204 * @param type Indicates the type used to format the phone number, includes: "E164", "RFC3966", "INTERNATIONAL", "NATIONAL". 205 * @since 8 206 */ 207 constructor(country: string, options?: PhoneNumberFormatOptions); 208 209 /** 210 * Judges whether phone number is valid. 211 * 212 * @syscap SystemCapability.Global.I18n 213 * @param number Indicates the input phone number to be judged. 214 * @return Returns a boolean indicates whether the input phone number is valid. 215 * @since 8 216 */ 217 isValidNumber(number: string): boolean; 218 219 /** 220 * Obtains the formatted phone number strings of number. 221 * 222 * @syscap SystemCapability.Global.I18n 223 * @param number Indicates the input phone number to be formatted. 224 * @return Returns the formatted phone number. 225 * @since 8 226 */ 227 format(number: string): string; 228} 229 230/** 231 * Get a Calendar instance specified by locale and type. 232 * 233 * @syscap SystemCapability.Global.I18n 234 * @param locale The locale used to get calendar. 235 * @param type If type is not specified, get locale's default Calendar, else get the specified type of Calendar. 236 * such as buddhist, chinese, coptic, ethiopic, hebrew, gregory, indian, islamic_civil, islamic_tbla, islamic_umalqura, 237 * japanese, persion. 238 * @since 8 239 */ 240 export function getCalendar(locale: string, type?: string): Calendar; 241 242export class Calendar { 243 /** 244 * set the date. 245 * 246 * @syscap SystemCapability.Global.I18n 247 * @param date Date object used to set the time and date. 248 * @since 8 249 */ 250 setTime(date: Date): void; 251 252 /** 253 * set the time. 254 * 255 * @syscap SystemCapability.Global.I18n 256 * @param time Indicates the elapsed milliseconds from 1970.1.1 00:00:00 GMT. 257 * @since 8 258 */ 259 setTime(time: number): void; 260 261 /** 262 * Set the time 263 * 264 * @syscap SystemCapability.Global.I18n 265 * @param year The year field of the calendar, ranges from 0 to 9999. 266 * @param month The month field of the calendar, ranges from 0 to 11. 267 * @param date The day field of the calendar, ranges from 1 to 31. 268 * @param hour The hour field of the calendar, ranges from 0 to 23. 269 * @param minute The minute field of the calendar, ranges from 0 to 59. 270 * @param second the second field of the calendar, ranges from 0 to 59. 271 * @since 8 272 */ 273 set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void; 274 275 /** 276 * Set the timezone of this calendar. 277 * 278 * @syscap SystemCapability.Global.I18n 279 * @param timezone The id of a timezone. 280 * @since 8 281 */ 282 setTimeZone(timezone: string): void; 283 284 /** 285 * Get the timezone id of this calendar instance. 286 * 287 * @syscap SystemCapability.Global.I18n 288 * @return Returns the timezone id of this calendar. 289 * @since 8 290 */ 291 getTimeZone(): string; 292 293 /** 294 * Get the start day of a week. 1 indicates Sunday, 7 indicates Saturday. 295 * 296 * @syscap SystemCapability.Global.I18n 297 * @return Returns start day of a week. 298 * @since 8 299 */ 300 getFirstDayOfWeek(): number; 301 302 /** 303 * Set the start day of a week. 1 indicates Sunday, 7 indicates Saturday. 304 * 305 * @syscap SystemCapability.Global.I18n 306 * @param value Indicates the start day of a week. 1 indicates Sunday, 7 indicates Saturday. 307 * @since 8 308 */ 309 setFirstDayOfWeek(value: number): void; 310 311 /** 312 * Get the minimal days of a week, which is needed for the first day of a year. 313 * 314 * @syscap SystemCapability.Global.I18n 315 * @return Returns the minimal days of a week. 316 * @since 8 317 */ 318 getMinimalDaysInFirstWeek(): number; 319 320 /** 321 * Set the minimal days of a week, which is needed for the first week of a year. 322 * 323 * @syscap SystemCapability.Global.I18n 324 * @param value The value to be set. 325 * @since 8 326 */ 327 setMinimalDaysInFirstWeek(value: number): void; 328 329 /** 330 * Get the associated value with the field. 331 * 332 * @syscap SystemCapability.Global.I18n 333 * @param field Field values such as era, year, month, week_of_year, week_of_month, date, day_of_year, day_of_week 334 * day_of_week_in_month, hour, hour_of_day, minute, second, millisecond, zone_offset, dst_offset, year_woy, 335 * dow_local, extended_year, julian_day, milliseconds_in_day, is_leap_month. 336 * @return Return the associated value. 337 * @since 8 338 */ 339 get(field: string): number; 340 341 /** 342 * Get calendar's name localized for display in the given locale. 343 * 344 * @syscap SystemCapability.Global.I18n 345 * @param locale Locale used to get the localized name for this calendar. 346 * @return Returns the localized name of this calendar. 347 * @since 8 348 */ 349 getDisplayName(locale: string): string; 350 351 /** 352 * Returns true if the given date is a weekend day. If the date is not given, 353 * the date object of this calendar is used. 354 * 355 * @syscap SystemCapability.Global.I18n 356 * @param date Date object whose attribute is desired. 357 * @return Returns whether the date is a weekend day. 358 * @since 8 359 */ 360 isWeekend(date?: Date): boolean; 361} 362 363/** 364 * Judge whether the locale is RTL locale. 365 * 366 * @syscap SystemCapability.Global.I18n 367 * @param locale The locale to be used. 368 * @return Returns true representing the locale is an RTL locale 369 * 370 * @since 7 371 */ 372export function isRTL(locale: string): boolean; 373 374/** 375 * Obtains a BreakIterator object for finding the location of break point in text. 376 * 377 * @syscap SystemCapability.Global.I18n 378 * @param locale the returned BreakIterator will adapt the rule, specified by the locale, to break text. 379 * @return Returns a newly constructed BreakIterator object. 380 * @since 8 381 */ 382 export function getLineInstance(locale: string): BreakIterator; 383 384/** 385 * The BreakIterator class is used for finding the location of break point in text. 386 * 387 * @syscap SystemCapability.Global.I18n 388 * @since 8 389 */ 390export class BreakIterator { 391 /** 392 * Obtains the current position of the BreakIterator instance. 393 * 394 * @syscap SystemCapability.Global.I18n 395 * @return Returns the current position of the BreakIterator instance. 396 * @since 8 397 */ 398 current(): number; 399 400 /** 401 * Set the BreakIterator's position to the first break point, the first break point is always the beginning of the 402 * processed text. 403 * 404 * @syscap SystemCapability.Global.I18n 405 * @return Returns the index of the first break point. 406 * @since 8 407 */ 408 first(): number; 409 410 /** 411 * Set the BreakIterator's position to the last break point. the last break point is always the index beyond the 412 * last character of the processed text. 413 * 414 * @syscap SystemCapability.Global.I18n 415 * @return Returns the index of the last break point. 416 * @since 8 417 */ 418 last(): number; 419 420 /** 421 * Set the BreakItertor's position to the nth break point from the current break point. 422 * 423 * @syscap SystemCapability.Global.I18n 424 * @param index indicates the number of break points to advance. If index is not given, n is treated as 1. 425 * @return Returns the index of the BreakIterator after moving. If there is not enough break points, returns -1. 426 * @since 8 427 */ 428 next(index?: number): number; 429 430 /** 431 * Set the BreakItertor's position to the break point preceding the current break point. 432 * 433 * @syscap SystemCapability.Global.I18n 434 * @return Returns the index of the BreakIterator after moving. If there is not enough break points, returns -1. 435 * @since 8 436 */ 437 previous(): number; 438 439 /** 440 * Set the text to be processed. 441 * 442 * @syscap SystemCapability.Global.I18n 443 * @param text Indicates the text to be processed by the BreakIterator. 444 * @since 8 445 */ 446 setLineBreakText(text: string): void; 447 448 /** 449 * Set the BreakIterator's position to the first break point following the specified offset. 450 * 451 * @syscap SystemCapability.Global.I18n 452 * @return Returns the index of the BreakIterator after moving. If there is not enough break points, returns -1. 453 * @since 8 454 */ 455 following(offset: number): number; 456 457 /** 458 * Obtains the text being processed. 459 * 460 * @syscap SystemCapability.Global.I18n 461 * @return Returns the text that is processed by the BreakIterator. 462 * @since 8 463 */ 464 getLineBreakText(): string; 465 466 /** 467 * Returns true if the position indicated by the offset is a break point, otherwise false. The BreakIterator's 468 * position will be set to the position indicated by the offset if it returns true, otherwise the BreakIterator 469 * will be moved to the break point following the offset. 470 * 471 * @syscap SystemCapability.Global.I18n 472 * @param offset The offset to be checked. 473 * @return Returns true if the offset is a break point. 474 * @since 8 475 */ 476 isBoundary(offset: number): boolean; 477} 478 479/** 480 * Get IndexUtil object. 481 * 482 * @syscap SystemCapability.Global.I18n 483 * @param locale Indicates a character string containing the locale information, including 484 * the language and optionally the script and region, for the NumberFormat object. 485 * @return Returns IndexUtil object. 486 * @since 8 487 */ 488export function getInstance(locale?:string): IndexUtil; 489 490/** 491 * Sequence text can be grouped under the specified area, 492 * and grouping index with different lengths can be specified. 493 * 494 * @syscap SystemCapability.Global.I18n 495 * @since 8 496 */ 497export class IndexUtil { 498 /** 499 * Get a list of labels for use as a UI index 500 * 501 * @syscap SystemCapability.Global.I18n 502 * @return Returns a list of labels 503 * @since 8 504 */ 505 getIndexList(): Array<string>; 506 507 /** 508 * Add the index characters from a Locale to the index. 509 * 510 * @syscap SystemCapability.Global.I18n 511 * @param locale The locale whose index characters are to be added. 512 * @since 8 513 */ 514 addLocale(locale: string): void; 515 516 /** 517 * Get corresponding index of the input text. 518 * 519 * @syscap SystemCapability.Global.I18n 520 * @param text input text 521 * @since 8 522 */ 523 getIndex(text: string): string; 524} 525 526/** 527 * Provides the API for accessing unicode character properties, sunch as whether a character is a digit. 528 * 529 * @syscap SystemCapability.Global.I18n 530 * @since 8 531 */ 532export class Character { 533 /** 534 * Determines whether the specified code point is a digit character 535 * 536 * @syscap SystemCapability.Global.I18n 537 * @param char the character to be tested 538 * @return Returns true if the character is a digit character 539 */ 540 isDigit(char: string): boolean; 541 542 /** 543 * Determines if the specified character is a space character or not. 544 * 545 * @syscap SystemCapability.Global.I18n 546 * @param char the character to be tested 547 * @return Returns true if the character is a space character 548 */ 549 isSpaceChar(char: string): boolean; 550 551 /** 552 * Determines if the specified character is a whitespace character 553 * 554 * @syscap SystemCapability.Global.I18n 555 * @param char the character to be tested 556 * @return Returns true if the character is a whitespace character 557 */ 558 isWhitespace(char: string): boolean; 559 560 /** 561 * Determines if the specified character is a RTL character or not. 562 * 563 * @syscap SystemCapability.Global.I18n 564 * @param char the character to be tested 565 * @return Returns true if the character is a RTL character 566 */ 567 isRTL(char: string): boolean; 568 569 /** 570 * Determines if the specified character is a Ideographic character or not. 571 * 572 * @syscap SystemCapability.Global.I18n 573 * @param char the character to be tested 574 * @return Returns true if the character is a Ideographic character 575 */ 576 isIdeograph(char: string): boolean; 577 578 /** 579 * Determines if the specified character is a Letter or not. 580 * 581 * @syscap SystemCapability.Global.I18n 582 * @param char the character to be tested 583 * @return Returns true if the character is a Letter 584 */ 585 isLetter(char: string): boolean; 586 587 /** 588 * Determines if the specified character is a LowerCase character or not. 589 * 590 * @syscap SystemCapability.Global.I18n 591 * @param char the character to be tested 592 * @return Returns true if the character is a LowerCase character 593 */ 594 isLowerCase(char: string): boolean; 595 596 /** 597 * Determines if the specified character is a UpperCase character or not. 598 * 599 * @syscap SystemCapability.Global.I18n 600 * @param char the character to be tested 601 * @return Returns true if the character is a UpperCase character 602 */ 603 isUpperCase(char: string): boolean; 604 605 /** 606 * Get the general category value of the specified character. 607 * 608 * @syscap SystemCapability.Global.I18n 609 * @param char the character to be tested 610 * @return Returns the general category of the specified character. 611 */ 612 getType(char: string): string; 613} 614 615/** 616 * check out whether system is 24-hour system. 617 * 618 * @syscap SystemCapability.Global.I18n 619 * @return Returns a boolean represent whether system is 24-hour system. 620 * @since 7 621 */ 622 export function is24HourClock(): boolean; 623 624/** 625 * set 24-hour system. 626 * 627 * @permission ohos.permission.UPDATE_CONFIGURATION 628 * @syscap SystemCapability.Global.I18n 629 * @param option represent the boolean to be set. 630 * @return Returns a boolean represent whether setting 24-hour system success. 631 * @since 7 632 */ 633 export function set24HourClock(option: boolean): boolean; 634 635/** 636 * Add one language to preferred language List. 637 * 638 * @permission ohos.permission.UPDATE_CONFIGURATION 639 * @syscap SystemCapability.Global.I18n 640 * @param language the language to be added. 641 * @param index the position of preferred language list to be inserted. 642 * @return Returns a boolean represent whether language added success. 643 * @since 8 644 */ 645export function addPreferredLanguage(language: string, index?: number): boolean; 646 647/** 648 * Remove one language from preferred language list. 649 * 650 * @permission ohos.permission.UPDATE_CONFIGURATION 651 * @syscap SystemCapability.Global.I18n 652 * @param index the position of removed language in preferred language list. 653 * @return Returns a boolean represent whether removed success. 654 * @since 8 655 */ 656export function removePreferredLanguage(index: number): boolean; 657 658/** 659 * Access the system preferred language list. 660 * 661 * @syscap SystemCapability.Global.I18n 662 * @return Returns a string Array represent the preferred language list. 663 * @since 8 664 */ 665export function getPreferredLanguageList(): Array<string>; 666 667/** 668 * Get the first preferred language of system. 669 * 670 * @syscap SystemCapability.Global.I18n 671 * @return Returns a string represent the first preferred language of system. 672 * @since 8 673 */ 674export function getFirstPreferredLanguage(): string; 675 676/** 677 * Get the default TimeZone object or the TimeZone object corresponds to zoneID. 678 * 679 * @syscap SystemCapability.Global.I18n 680 * @param zoneID TimeZone ID used to create TimeZone Object. 681 * @return Returns a TimeZone object corresponds to zoneID. 682 * @since 7 683 */ 684export function getTimeZone(zoneID?: string): TimeZone; 685 686/** 687 * Provides the API for accessing TimeZone name, rawOffset and offset information. 688 * 689 * @syscap SystemCapability.Global.I18n 690 * @since 7 691 */ 692export class TimeZone { 693 /** 694 * Get the id of the TimeZone object. 695 * 696 * @syscap SystemCapability.Global.I18n 697 * @return Returns a string represents the timezone id. 698 * @since 7 699 */ 700 getID(): string; 701 702 /** 703 * Get the displayName of the TimeZone Object under the locale. 704 * 705 * @syscap SystemCapability.Global.I18n 706 * @param locale the locale tag use to display timezone object's name. 707 * @param isDST wether conside daylight saving time when display timezone object's name. 708 * @return Returns a string represents the display name. 709 * @since 7 710 */ 711 getDisplayName(locale?: string, isDST?: boolean): string; 712 713 /** 714 * Get the raw offset of the TimeZone object. 715 * 716 * @syscap SystemCapability.Global.I18n 717 * @return Returns a number represents the raw offset. 718 * @since 7 719 */ 720 getRawOffset(): number; 721 722 /** 723 * Get the offset of the TimeZone object. 724 * 725 * @syscap SystemCapability.Global.I18n 726 * @date Indicates a date use to compute offset. 727 * @return Returns a number represents the offset with date. 728 * @since 7 729 */ 730 getOffset(date?: number): number; 731} 732} 733export default i18n;