This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Make Locale know about the deprecated Hebrew language code. #4411
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:ui'; | ||
|
||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test('Locale', () { | ||
final Null $null = null; | ||
expect(const Locale('en').toString(), 'en'); | ||
expect(const Locale('en'), new Locale('en', $null)); | ||
expect(const Locale('en').hashCode, new Locale('en', $null).hashCode); | ||
expect(const Locale('en'), isNot(new Locale('en', '')))); | ||
expect(const Locale('en').hashCode, isNot(new Locale('en', '').hashCode)); | ||
expect(const Locale('en', 'US').toString(), 'en_US'); | ||
expect(const Locale('iw').toString(), 'he'); | ||
expect(const Locale('iw', 'DD').toString(), 'he_DE'); | ||
expect(const Locale('iw', 'DD'), const Locale('he', 'DE')); | ||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2017 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// This file is used to generate the switch statements in the Locale class. | ||
// See: ../lib/ui/window.dart | ||
|
||
// When running this script, use the output of this script to update the | ||
// comments that say when the script was last run (that comment appears twice in | ||
// window.dart), and then replace all the "case" statements with the output from | ||
// this script (the first set for _canonicalizeLanguageCode and the second set | ||
// for _canonicalizeRegionCode). | ||
|
||
import 'dart:async'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment that explains what this app is for (even though we may not run it very often) would be good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
const String registry = 'https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry'; | ||
|
||
Map<String, List<String>> parseSection(String section) { | ||
final Map<String, List<String>> result = <String, List<String>>{}; | ||
List<String> lastHeading; | ||
for (String line in section.split('\n')) { | ||
if (line == '') | ||
continue; | ||
if (line.startsWith(' ')) { | ||
lastHeading[lastHeading.length - 1] = '${lastHeading.last}${line.substring(1)}'; | ||
continue; | ||
} | ||
final int colon = line.indexOf(':'); | ||
if (colon <= 0) | ||
throw 'not sure how to deal with "$line"'; | ||
final String name = line.substring(0, colon); | ||
final String value = line.substring(colon + 2); | ||
lastHeading = result.putIfAbsent(name, () => <String>[]); | ||
result[name].add(value); | ||
} | ||
return result; | ||
} | ||
|
||
Future<Null> main() async { | ||
final HttpClient client = new HttpClient(); | ||
final String body = (await (await (await client.getUrl(Uri.parse(registry))).close()).transform(UTF8.decoder).toList()).join(''); | ||
final List<Map<String, List<String>>> sections = body.split('%%').map<Map<String, List<String>>>(parseSection).toList(); | ||
final Map<String, List<String>> outputs = <String, List<String>>{'language': <String>[], 'region': <String>[]}; | ||
String fileDate; | ||
for (Map<String, List<String>> section in sections) { | ||
if (fileDate == null) { | ||
// first block should contain a File-Date metadata line. | ||
fileDate = section['File-Date'].single; | ||
continue; | ||
} | ||
assert(section.containsKey('Type'), section.toString()); | ||
final String type = section['Type'].single; | ||
if ((type == 'language' || type == 'region') && (section.containsKey('Preferred-Value'))) { | ||
assert(section.containsKey('Subtag'), section.toString()); | ||
final String subtag = section['Subtag'].single; | ||
final List<String> descriptions = section['Description']; | ||
assert(descriptions.isNotEmpty); | ||
assert(section.containsKey('Deprecated')); | ||
final String comment = section.containsKey('Comment') ? section['Comment'].single : 'deprecated ${section['Deprecated'].single}'; | ||
final String preferredValue = section['Preferred-Value'].single; | ||
outputs[type].add('case \'$subtag\': return \'$preferredValue\'; // ${descriptions.join(", ")}; $comment'); | ||
} | ||
} | ||
print('// Mappings generated for language subtag registry as of $fileDate.'); | ||
print('// For languageCode:'); | ||
print(outputs['language'].join('\n')); | ||
print('// For regionCode:'); | ||
print(outputs['region'].join('\n')); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NICE. No more `const Locale('foo', '')