1/* 2* Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 type common from '@ohos.app.ability.common'; 17 18class ResourceUtil { 19 async getString(id: number, context: common.Context): Promise<string> { 20 let rscManager = context.resourceManager; 21 let str: string = await rscManager.getStringValue(id); 22 return str; 23 } 24 25 async getStringArray(id: number, context: common.Context): Promise<Array<string>> { 26 let rscManager = context.resourceManager; 27 let strArray: Array<string> = await rscManager.getStringArrayValue(id); 28 return strArray; 29 } 30 31 async getPluralString(id: number, num: number, context: common.Context): Promise<string> { 32 let rscManager = context.resourceManager; 33 let plural: string = await rscManager.getPluralStringValue(id, num); 34 return plural; 35 } 36 37 async getDirection(context: common.Context): Promise<string> { 38 let rscManager = context.resourceManager; 39 let configuration = await rscManager.getConfiguration(); 40 if (configuration.direction === 1) { // 1代表Horizontal,0代表Vertical 41 return 'Horizontal'; 42 } else { 43 return 'Vertical'; 44 } 45 } 46} 47 48export default new ResourceUtil();