Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
aa39fa5a
Unverified
Commit
aa39fa5a
authored
May 12, 2022
by
Alex Li
Committed by
GitHub
May 12, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[gen_l10n] Better blank lines in the header of generated files (#103414)
parent
78885ecb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
17 deletions
+71
-17
gen_l10n.dart
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
+3
-3
gen_l10n_templates.dart
...utter_tools/lib/src/localizations/gen_l10n_templates.dart
+9
-13
generate_localizations_test.dart
...tools/test/general.shard/generate_localizations_test.dart
+59
-1
No files found.
packages/flutter_tools/lib/src/localizations/gen_l10n.dart
View file @
aa39fa5a
...
...
@@ -1133,14 +1133,14 @@ class LocalizationsGenerator {
});
return
classFileTemplate
.
replaceAll
(
'@(header)'
,
header
)
.
replaceAll
(
'@(header)'
,
header
.
isEmpty
?
''
:
'
$header
\n\n
'
)
.
replaceAll
(
'@(language)'
,
describeLocale
(
locale
.
toString
()))
.
replaceAll
(
'@(baseClass)'
,
className
)
.
replaceAll
(
'@(fileName)'
,
fileName
)
.
replaceAll
(
'@(class)'
,
'
$className${locale.camelCase()}
'
)
.
replaceAll
(
'@(localeName)'
,
locale
.
toString
())
.
replaceAll
(
'@(methods)'
,
methods
.
join
(
'
\n\n
'
))
.
replaceAll
(
'@(requiresIntlImport)'
,
_requiresIntlImport
()
?
"import 'package:intl/intl.dart' as intl;"
:
''
);
.
replaceAll
(
'@(requiresIntlImport)'
,
_requiresIntlImport
()
?
"import 'package:intl/intl.dart' as intl;
\n\n
"
:
''
);
}
String
_generateSubclass
(
...
...
@@ -1284,7 +1284,7 @@ class LocalizationsGenerator {
);
return
fileTemplate
.
replaceAll
(
'@(header)'
,
header
)
.
replaceAll
(
'@(header)'
,
header
.
isEmpty
?
''
:
'
$header
\n
'
)
.
replaceAll
(
'@(class)'
,
className
)
.
replaceAll
(
'@(methods)'
,
_allMessages
.
map
((
Message
message
)
=>
generateBaseClassMethod
(
message
,
_templateArbLocale
)).
join
(
'
\n
'
))
.
replaceAll
(
'@(importFile)'
,
'
$directory
/
$outputFileName
'
)
...
...
packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart
View file @
aa39fa5a
...
...
@@ -9,8 +9,7 @@ description: The Flutter application's synthetic package.
''';
const String fileTemplate = '''
@
(
header
)
import
'dart:async'
;
@
(
header
)
import
'dart:async'
;
@
(
requiresFoundationImport
)
import
'package:flutter/widgets.dart'
;
...
...
@@ -19,14 +18,14 @@ import 'package:intl/intl.dart' as intl;
@
(
messageClassImports
)
/// Callers can lookup localized strings with an instance of @(class)
returned
/// by `@(class).of(context)`.
/// Callers can lookup localized strings with an instance of @(class)
///
returned
by `@(class).of(context)`.
///
/// Applications need to include `@(class).delegate()` in their app's
///
localizationDelegates
list, and the locales they support in the app's
///
supportedLocales
list. For example:
///
`localizationDelegates`
list, and the locales they support in the app's
///
`supportedLocales`
list. For example:
///
/// ```
/// ```
dart
/// import '@(importFile)';
///
/// return MaterialApp(
...
...
@@ -41,14 +40,14 @@ import 'package:intl/intl.dart' as intl;
/// Please make sure to update your pubspec.yaml to include the following
/// packages:
///
/// ```
/// ```
yaml
/// dependencies:
/// # Internationalization support.
/// flutter_localizations:
/// sdk: flutter
/// intl: any # Use the pinned version from flutter_localizations
///
/// #
r
est of dependencies
/// #
R
est of dependencies
/// ```
///
/// ## iOS Applications
...
...
@@ -202,10 +201,7 @@ const String selectMethodTemplateInString = '''
}
''';
const String classFileTemplate = '''
@
(
header
)
@
(
requiresIntlImport
)
import
'@(fileName)'
;
@
(
header
)
@
(
requiresIntlImport
)
import
'@(fileName)'
;
/// The translations for @(language) (`@(localeName)`).
class
@(
class
)
extends
@
(
baseClass
)
{
...
...
packages/flutter_tools/test/general.shard/generate_localizations_test.dart
View file @
aa39fa5a
...
...
@@ -789,7 +789,6 @@ void main() {
expect
(
fs
.
file
(
'/lib/l10n/bar_en.dart'
).
readAsStringSync
(),
'''
HEADER
import '
bar
.
dart
';
/// The translations for English (`en`).
...
...
@@ -839,6 +838,65 @@ flutter:
),
);
});
testWithoutContext
(
'blank lines generated nicely'
,
()
async
{
_standardFlutterDirectoryL10nSetup
(
fs
);
// Test without headers.
generateLocalizations
(
fileSystem:
fs
,
options:
LocalizationOptions
(
arbDirectory:
Uri
.
directory
(
defaultL10nPathString
),
outputDirectory:
Uri
.
directory
(
defaultL10nPathString
,
windows:
false
),
templateArbFile:
Uri
.
file
(
defaultTemplateArbFileName
,
windows:
false
),
useSyntheticPackage:
false
,
),
logger:
BufferLogger
.
test
(),
projectDir:
fs
.
currentDirectory
,
dependenciesDir:
fs
.
currentDirectory
,
);
expect
(
fs
.
file
(
'/lib/l10n/app_localizations_en.dart'
).
readAsStringSync
(),
'''
import '
app_localizations
.
dart
';
/// The translations for English (`en`).
class AppLocalizationsEn extends AppLocalizations {
AppLocalizationsEn([String locale = '
en
']) : super(locale);
@override
String get title => '
Title
';
}
'''
);
// Test with headers.
generateLocalizations
(
fileSystem:
fs
,
options:
LocalizationOptions
(
header:
'HEADER'
,
arbDirectory:
Uri
.
directory
(
defaultL10nPathString
),
outputDirectory:
Uri
.
directory
(
defaultL10nPathString
,
windows:
false
),
templateArbFile:
Uri
.
file
(
defaultTemplateArbFileName
,
windows:
false
),
useSyntheticPackage:
false
,
),
logger:
BufferLogger
.
test
(),
projectDir:
fs
.
currentDirectory
,
dependenciesDir:
fs
.
currentDirectory
,
);
expect
(
fs
.
file
(
'/lib/l10n/app_localizations_en.dart'
).
readAsStringSync
(),
'''
HEADER
import '
app_localizations
.
dart
';
/// The translations for English (`en`).
class AppLocalizationsEn extends AppLocalizations {
AppLocalizationsEn([String locale = '
en
']) : super(locale);
@override
String get title => '
Title
';
}
'''
);
});
});
group
(
'loadResources'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment