Skip to content

Commit

Permalink
♻️ Improve the conversion from text to key
Browse files Browse the repository at this point in the history
  • Loading branch information
lsaudon committed Nov 4, 2022
1 parent 03e6432 commit 9116015
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/localizationActionProvider.ts
Original file line number Diff line number Diff line change
@@ -76,12 +76,16 @@ export class LocalizationActionProvider implements vscode.CodeActionProvider {
}

private camelize(value: string): string {
const regex = /(?:^\w|[A-Z]|\b\w|\s+)/gu;
return value.replace(regex, (match: string, index: number) => {
if (+Number(match) === 0) {
return '';
const valueSplitted = value.split(/[^a-zA-Z0-9]/u);
let result = '';
for (let index = 0; index < valueSplitted.length; index += 1) {
let element = valueSplitted[index];
element = element.toLowerCase();
if (index !== 0) {
element = element.charAt(0).toUpperCase() + element.substring(1);
}
return index === 0 ? match.toLowerCase() : match.toUpperCase();
});
result += element;
}
return result;
}
}
2 changes: 1 addition & 1 deletion src/test/suite/my_other_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ class App extends StatelessWidget {
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(
appBar: AppBar(title: Text(l10n.counterAppBarTitle)),
body: const Center(child: Text("Hello World")),
body: const Center(child: Text("Aujourd'hui il FAIT 50°C.")),
),
);
}

0 comments on commit 9116015

Please sign in to comment.