• Home
  • Raw
  • Download

Lines Matching +full:locales +full:- +full:all

3 # Use of this source code is governed by a BSD-style license that can be
6 """Helper script used to manage locale-related files in Chromium.
8 This script is used to check, and potentially fix, many locale-related files
11 - GRIT input files (.grd) and the corresponding translations (.xtb).
13 - BUILD.gn files listing Android localized resource string resource .xml
14 generated by GRIT for all supported Chrome locales. These correspond to
17 The --scan-dir <dir> option can be used to check for all files under a specific
18 directory, and the --fix-inplace option can be used to try fixing any file
22 translations / locales to the Chrome code base, since this script can update
26 remoting/resources/remoting_strings.grd contains an in-line comment element
54 _DEFAULT_LOCALE = 'en-US'
73 'en': 'en-US', # For now, Chromium doesn't have an 'en' locale.
74 'iw': 'he', # 'iw' is the obsolete form of ISO 639-1 for Hebrew
92 list_a: First list of locales.
93 list_expected: Second list of locales, as expected.
99 missing_locales = sorted(set(list_a) - set(list_expected))
101 errors.append('Missing locales: %s' % missing_locales)
103 extra_locales = sorted(set(list_expected) - set(list_a))
105 errors.append('Unexpected locales: %s' % extra_locales)
124 A list of (start_pos, end_pos) tuples, where all items in
149 """Sort an input list's sub-range according to a specific key function.
153 start: Sub-range starting position in list.
154 end: Sub-range limit position in list.
157 A copy of |input_list|, with all items in [|start|, |end|) sorted
175 """Sort all elements of a given type in a list of lines by a given key.
192 def _ProcessFile(input_file, locales, check_func, fix_func): argument
197 locales: List of Chrome locales to consider / expect.
199 (input_lines, locales) argument. It must return an list of error
202 (input_lines, locales). It must return the new list of lines for
211 errors = check_func(input_file, input_lines, locales)
216 input_lines = fix_func(input_file, input_lines, locales)
221 except Exception as e: # pylint: disable=broad-except
231 scan_dir: A list of top-level directories to start scan in.
261 # have to guess the platform-specific sub-directory name (e.g. 'linux64'
262 # for 64-bit Linux machines).
323 # Various list of locales that will be extracted from build/config/locales.gni
331 """Return the list of all locales supported by Chrome."""
338 """Return the list of locales that are unsupported on iOS."""
347 This allows us to run 'gn gen <out> --root <work_dir>' as fast as possible
348 to generate files containing the locales list. This takes about 300ms on
355 out_subdir_name: Name of output sub-directory.
359 # Create top-level .gn file that must point to the BUILDCONFIG.gn.
363 # all variables that may be used in locales.gni in a declare_args() block.
383 # Create top-level BUILD.gn, GN requires at least one target to build so do
384 # that with a fake action which will never be invoked. Also write the locales
387 os.path.join(work_dir, 'BUILD.gn'), r'''import("//locales.gni")
395 # Write the locales lists to files in the output directory.
397 write_file(_filename + ".locales", locales, "json")
403 # Copy build/config/locales.gni to the workspace, as required by BUILD.gn.
404 shutil.copyfile(os.path.join(_TOP_SRC_DIR, 'build', 'config', 'locales.gni'),
405 os.path.join(work_dir, 'locales.gni'))
417 # the locales list extraction process.
439 # build/config/locales.gni
443 [gn_executable, 'gen', out_path, '--root=' + tmp_path])
450 os.path.join(out_path, 'foo.locales'))
469 # tends to re-order attributes in each element when re-writing an XML
472 # Thus simple line-based regular expression matching is used instead.
505 '<file lang="fr-CA" path="path/to/strings_fr-CA.xtb" />': 'fr-CA',
514 """Sort all .grd elements of a given type by their lang attribute."""
522 - Each item has a correct 'lang' attribute.
523 - There are no duplicated lines for the same 'lang' attribute.
524 - That there are no extra locales that Chromium doesn't want.
525 - That no wanted locale is missing.
529 start: Sub-range start position in input line list.
530 end: Sub-range limit position in input line list.
536 locales = set()
545 if cr_locale in locales:
548 locales.add(cr_locale)
550 extra_locales = locales.difference(wanted_locales)
552 errors.append('%d-%d: Extra locales found: %s' % (start + 1, end + 1,
555 missing_locales = wanted_locales.difference(locales)
557 errors.append('%d-%d: Missing locales: %s' % (start + 1, end + 1,
572 """Returns True iff this is an Android-specific <output> line."""
581 # pylint: disable=unused-argument
585 """Check all <output> elements in specific input .grd lines range.
588 - Filenames exist for each listed locale.
589 - Filenames are well-formed.
593 start: Sub-range start position in input line list.
594 end: Sub-range limit position in input line list.
618 prefix = ('values-%s' % resource_utils.ToAndroidLocaleName(cr_locale)
628 """Check all <output> elements related to Android.
655 for locales from |wanted_locales| that were not part of the input.
659 locales = set()
663 locales.add(locale)
665 missing_locales = wanted_locales.difference(locales)
681 line_count = end - 1
686 'values-%s/' % src_locale, 'values-%s/' % android_locale)
715 '<file lang="fr-CA" path="translations/aw_strings_fr-CA.xtb"/>',
716 '<file lang="fr-CA" path="translations/aw_strings_fr-CA.xtb" />',
734 """Check all <translations> sub-elements in specific input .grd lines range.
737 - Each item has a 'path' attribute.
738 - Each such path value ends up with '.xtb'.
742 start: Sub-range start position in input line list.
743 end: Sub-range limit position in input line list.
768 """Check all <file> elements that correspond to an .xtb output file.
777 wanted_locales = wanted_locales - set([_DEFAULT_LOCALE])
818 This also creates fake .xtb files from the one provided for 'en-GB'.
826 for locales from |wanted_locales| that were not part of the input.
828 wanted_locales = wanted_locales - set([_DEFAULT_LOCALE])
831 locales = set()
835 locales.add(locale)
837 missing_locales = wanted_locales.difference(locales)
841 src_locale = 'en-GB'
857 line_count = end - 1
882 r'^\s*".*values(\-([A-Za-z0-9-]+))?/.*\.xml",\s*$')
902 """Returns True iff this is an Android-specific localized .xml output."""
909 Special case: Some BUILD.gn files list several non-localized .xml files
922 These are non-localized strings, and should be ignored. This function is
936 locales = set()
942 if cr_locale in locales:
945 locales.add(cr_locale)
947 extra_locales = locales.difference(wanted_locales)
949 errors.append('%d-%d: Extra locales: %s' % (start + 1, end + 1,
952 missing_locales = wanted_locales.difference(locales)
954 errors.append('%d-%d: Missing locales: %s' % (start + 1, end + 1,
977 locales = set()
981 locales.add(locale)
983 missing_locales = wanted_locales.difference(locales)
988 src_values = 'values-%s/' % resource_utils.ToAndroidLocaleName(src_locale)
999 line_count = end - 1
1002 dst_line = src_line.replace('values-%s/' % src_locale, 'values/')
1005 'values-%s/' % src_locale,
1006 'values-%s/' % resource_utils.ToAndroidLocaleName(locale))
1046 """Update the locales list(s) found in an expectations file.
1052 to word-wrap the new list items.
1072 # Skip over all lines from the list.
1082 locale_width = available_width - (start_margin + 2)
1158 """Update all locales listed in a given expectations file.
1162 wanted_locales: List of locales that need to be written to
1167 for locale in set(wanted_locales) - set([_DEFAULT_LOCALE])
1186 # pylint: enable=unused-argument
1225 """A base class for all commands recognized by this script.
1228 1) Derived classes must re-define the following class-based fields:
1229 - name: Command name (e.g. 'list-locales')
1230 - description: Command short description.
1231 - long_description: Optional. Command long description.
1237 sub-parser as argument.
1268 """Implement the 'list-locales' command to list locale lists of interest."""
1269 name = 'list-locales'
1270 description = 'List supported Chrome locales'
1272 List locales of interest, by default this prints all locales supported by
1273 Chrome, but `--type=ios_unsupported` can be used for the list of locales
1276 These values are extracted directly from build/config/locales.gni.
1278 Additionally, use the --as-json argument to print the list as a JSON list,
1279 instead of the default format (which is a space-separated list of locale names).
1282 # Maps type argument to a function returning the corresponding locales list.
1284 'all': ChromeLocales,
1290 '--as-json',
1294 '--type',
1296 default='all',
1310 Subclasses should also define the following class-level variables:
1312 - select_file_func:
1315 '--scan-dir <dir>'.
1317 - check_func:
1318 - fix_func:
1328 '--scan-dir',
1336 '--fix-inplace',
1338 help='Try to fix the files in-place too.')
1340 '--add-locales',
1341 help='Space-separated list of additional locales to use')
1351 locales = ChromeLocales()
1353 locales.extend(args.add_locales.split(' '))
1355 locales = set(locales)
1359 locales,
1366 name = 'check-grd-android-outputs'
1373 - Each item has a correct 'lang' attribute.
1374 - There are no duplicated lines for the same 'lang' attribute.
1375 - That there are no extra locales that Chromium doesn't want.
1376 - That no wanted locale is missing.
1377 - Filenames exist for each listed locale.
1378 - Filenames are well-formed.
1386 name = 'check-grd-translations'
1393 - Each item has a correct 'lang' attribute.
1394 - There are no duplicated lines for the same 'lang' attribute.
1395 - That there are no extra locales that Chromium doesn't want.
1396 - That no wanted locale is missing.
1397 - Each item has a 'path' attribute.
1398 - Each such path value ends up with '.xtb'.
1406 name = 'check-gn-android-outputs'
1412 - There are no duplicated output files in the list.
1413 - Each output file belongs to a wanted Chromium locale.
1414 - There are no output files for unwanted Chromium locales.
1422 name = 'check-all'
1424 long_description = 'Equivalent to calling all other check-xxx commands.'
1431 name = 'update-expectations'
1434 Update %s files to match the current list of locales supported by Chromium.
1435 This is especially useful to add new locales before updating any GRIT or GN
1436 input file with the --add-locales option.
1441 '--add-locales',
1442 help='Space-separated list of additional locales to use.')
1445 locales = ChromeLocales()
1448 locales.extend(add_locales.split(' '))
1460 _UpdateLocalesInExpectationFile(file_path, locales)
1468 name = 'unit-tests'
1469 description = 'Run internal unit-tests for this script'
1473 '-v', '--verbose', action='count', help='Increase test verbosity.')
1481 # List of all commands supported by this script.
1503 argv = ['--help']