generate_embedded_i18n.gni 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # Copyright 2018 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import("//build/config/chrome_build.gni")
  5. import("//build/config/locales.gni")
  6. # This template defines a rule to generate localized string .rc and .h files
  7. # that can be embedded directly into a library or executable if desired
  8. #
  9. # Parameters
  10. #
  11. # grd_files_info
  12. # List of tuples that contains information about the all the .grd files
  13. # from which to extract the strings.
  14. # Each tuple contains 4 elements:
  15. # 1. The folder containing the grd file.
  16. # 2. The name of the grd file without an extension.
  17. # 3. The path relative to the grd file where the xtb files are stored.
  18. # 4. The expected locales of the xtb files available in the xtb
  19. # relative path (can use default_embedded_i18_locales defined in
  20. # this file). This is just the locale portion of the filename so
  21. # if a file like google_strings_en-US.xtb is expected then this
  22. # list should contain "en-US".
  23. #
  24. # output_file_name_base
  25. # The base name of the generated header / rc file that will contain the
  26. # extracted string information. The files will be output to:
  27. # "$target_gen_dir/$output_file_name_base.h" and
  28. # "$target_gen_dir/$output_file_name_base.rc".
  29. #
  30. # first_resource_id (optional)
  31. # The starting resource ID for the generated string resources.
  32. # Defaults to 1600.
  33. #
  34. # extractor_datafile (optional)
  35. # The python file to execute that contains definition of the specific strings
  36. # to extract from the source .grd. This file can contain an array STRING_IDS
  37. # that lists all the IDs that will be extracted for all brand targets.
  38. # It can optionally also contain a dictionary MODE_SPECIFIC_STRINGS that
  39. # contains mode specific strings for certain brand targets.
  40. # MODE_SPECIFIC_STRINGS is only valid if STRING_IDS is specified.
  41. # Will not be passed to the generation script if it is undefined.
  42. #
  43. # branding (optional)
  44. # The branding used to determine specific string extractions.
  45. # Will not be passed to the generation script if it is undefined.
  46. #
  47. # deps (optional)
  48. # visibility (optional)
  49. # Locales in |all_chrome_locales| are for pak file format. We need to convert them
  50. # to the xtb version.
  51. default_embedded_i18_locales = all_chrome_locales - [
  52. "en-US",
  53. "he",
  54. "nb",
  55. ] +
  56. [
  57. "iw",
  58. "no",
  59. ] - pseudolocales
  60. template("generate_embedded_i18n") {
  61. assert(defined(invoker.grd_files_info),
  62. "Grd file information must be defined for $target_name")
  63. assert(defined(invoker.output_file_name_base),
  64. "Output file name base must be defined for $target_name")
  65. if (defined(invoker.extractor_datafile)) {
  66. extractor_datafile = invoker.extractor_datafile
  67. }
  68. grd_files_info = invoker.grd_files_info
  69. output_file_name_base = invoker.output_file_name_base
  70. if (defined(invoker.branding)) {
  71. branding = invoker.branding
  72. }
  73. first_resource_id = "1600"
  74. if (defined(invoker.first_resource_id)) {
  75. first_resource_id = invoker.first_resource_id
  76. }
  77. action(target_name) {
  78. script = "//base/win/embedded_i18n/create_string_rc.py"
  79. inputs = []
  80. output_dir = rebase_path(target_gen_dir, root_build_dir)
  81. output_header = "$target_gen_dir/$output_file_name_base.h"
  82. output_rc = "$target_gen_dir/$output_file_name_base.rc"
  83. outputs = [
  84. output_header,
  85. output_rc,
  86. ]
  87. args = [
  88. "--header-file",
  89. "$output_dir/$output_file_name_base.h",
  90. "--rc-file",
  91. "$output_dir/$output_file_name_base.rc",
  92. "--first-resource-id",
  93. first_resource_id,
  94. ]
  95. foreach(grd_file_info, grd_files_info) {
  96. grdfile_folder = grd_file_info[0]
  97. grdfile_name = grd_file_info[1]
  98. xtb_relative_path = grd_file_info[2]
  99. grd_file = "$grdfile_folder/$grdfile_name.grd"
  100. resource_path = "$grdfile_folder/$xtb_relative_path"
  101. inputs += [ grd_file ]
  102. args += [
  103. "-i",
  104. rebase_path(grd_file, root_build_dir),
  105. "-r",
  106. xtb_relative_path,
  107. ]
  108. # Lists must be reset to empty before being assigned a new list
  109. xtb_locales = []
  110. xtb_locales = grd_file_info[3]
  111. foreach(locale, xtb_locales) {
  112. expected_xtb_input = "${resource_path}/${grdfile_name}_${locale}.xtb"
  113. args += [
  114. "-x",
  115. rebase_path(expected_xtb_input, root_build_dir),
  116. ]
  117. inputs += [ expected_xtb_input ]
  118. }
  119. }
  120. if (defined(extractor_datafile)) {
  121. inputs += [ extractor_datafile ]
  122. args += [
  123. "--extract-datafile",
  124. rebase_path(extractor_datafile, root_build_dir),
  125. ]
  126. }
  127. if (defined(branding)) {
  128. args += [
  129. "-b",
  130. branding,
  131. ]
  132. }
  133. forward_variables_from(invoker, [ "deps" ])
  134. forward_variables_from(invoker, [ "visibility" ])
  135. }
  136. }