目录

Visual Editing of String Resources

Overview

During app development, string resources are scattered in multiple directories (such as resources/base/element/string.json, resources/zh_CN/element/string.json, and resources/en_US/element/string.json). Manually switching between files to view and edit these resources is inefficient.

The visual editing capability for string resources displays information of all string resources (including their names, values, and directories) in a unified table to improve readability. In addition, it allows you to create new resources in the visual UI, and edit resource values, copy/paste resources, and delete resources directly in the table, improving development efficiency. This feature is applicable to scenarios involving multi-language/multi-device adaptation, cross-project/cross-module sharing of string resources, and resource localization.

Procedure

  1. Double-click the string.json file in the resources directory and click Open editor in the editor pane to open the visual editing page for string resources.

  2. An example of the visual table for string resources is shown below. The Name column displays the resource names, Resource Folder displays the resource directories, base displays the resource values in the default resource directory, and the columns after base (such as aa_ET-wearable) display the resource values in the qualifier directories.

    Qualifier directories are arranged alphabetically in the columns following the base column.

  3. On the visual editing page, you can create string resources and qualifier directories, filter qualifier directories, and edit table content.

    • Creating a resource in the base directory

      Click at the top to open the wizard for creating a string resource. Enter the resource name (Name) and the resource value (Value), select a resource directory (Resource folder), and click OK. After the resource is created, it will be written into the corresponding string.json file and displayed in the visual table.

    • Creating a qualifier directory

      Click at the top to open the wizard for creating a qualifier. Select the resource directory path via Source set, select a qualifier under Available qualifiers, and click OK. Once created, the qualifier directory is displayed synchronously in both the project directory and the table.

    • Filtering qualifier directories

      The filter box at the top allows you to filter qualifier directories and defaults to Show All Qualifiers. After you select a qualifier, the table displays the Name column, Resource Folder column, base column, and the selected qualifier columns.

    • Editing resource values

      Select a cell in the base column or a qualifier directory column to display and edit its current value in the input box at the top, or double-click a resource value cell to enter edit mode directly. After editing, click outside the cell to lose focus or press Enter to save the changes. The updated resource value is written to the corresponding string.json file and displayed synchronously in the visual table.

    • Selecting multiple resources

      This feature is supported since version 26.0.1. You can use the following keyboard and mouse combinations to select multiple rows in the table simultaneously. Once multiple rows are selected, you can perform batch operations such as batch copy and paste or batch deletion.

      • Ctrl+Click (Command+Click on macOS): Selects or deselects a row to toggle its selection state.
      • Ctrl+Shift+Click (Command+Shift+Click on macOS): Continuously selects rows from the currently selected row to the target row.
      • Click: Cancels multi-row selection and switches to the single-cell selection mode.

        Clicking the refresh button cancels multi-row selection.

    • Copying resources

      This feature is supported since version 26.0.1. Right-click a selected cell or row in the table and choose Copy Line to serialize the selected data into JSON format and write it to the system pasteboard. Both single-row and multi-row copying are supported.

    • Pasting resources

      This feature is supported since version 26.0.1. Right-click in the visual table of the target module or project and choose Create & Paste Line to paste the copied resource content. During pasting, resources are added only to the qualifier directories that already exist in the target module or project.

      If the pasted data contains resources with the same names as existing ones in the current table, a dialog box pops up with the following options:

      • Cancel: Cancel the paste operation.
      • Ignore: Create only non-conflicting items and skip resources with the same names.
      • Overwrite: Overwrite resources with the same names using the new values.

    • Navigating to the source string.json file and resource declaration

      Right-click a selected non-empty cell and choose Go to Declaration to open the corresponding string.json file and navigate to the string declaration.

      Selecting a cell in the Name, Resource Folder, or base column navigates to the string.json file in the base directory, whereas selecting a cell in a qualifier directory column (such as aa) navigates to the string.json file in the corresponding qualifier directory.

    • Deleting a resource value

      Right-click a selected resource value under the base directory or a qualifier directory, and choose Delete string to delete the selected resource value.

    • Deleting a resource

      Right-click a selected cell in the Name or Resource Folder column, choose Delete key, and click OK in the confirmation dialog box that pops up to delete the corresponding resource from the base directory and the qualifier directories.

      This feature is supported since version 26.0.1. Right-click multiple selected rows in the visual table, choose Delete key, and click OK in the confirmation dialog box that pops up to delete the corresponding resources in batches from the base directory and the qualifier directories.