Skip to content

Commit 77fb389

Browse files
committed
Add --missing-languages filter to strings
1 parent f4d9fd2 commit 77fb389

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# xcstrings-cli
22

3+
## 2.5.0
4+
5+
### Minor Changes
6+
7+
- Add --missing-languages option to `strings` command
8+
39
## 2.4.0
410

511
### Minor Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xcstrings-cli",
3-
"version": "2.4.0",
3+
"version": "2.5.0",
44
"description": "A command line tool for handling xcstrings files.",
55
"type": "module",
66
"bin": {

src/commands/strings.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface FilterSpec {
1313
export interface ListOptions {
1414
path: string;
1515
languages?: string[];
16+
missingLanguages?: string[];
1617
keyFilter?: FilterSpec;
1718
textFilter?: FilterSpec;
1819
format?: string;
@@ -61,6 +62,11 @@ export function createStringsCommand(): CommandModule {
6162
alias: 'l',
6263
describe: 'Include only these languages',
6364
})
65+
.option('missing-languages', {
66+
type: 'string',
67+
array: true,
68+
describe: 'Include only keys missing any of these languages',
69+
})
6470
.option('format', {
6571
type: 'string',
6672
describe: 'Mustache template. Available variables: {{language}}, {{key}}, {{text}}',
@@ -101,6 +107,7 @@ export function createStringsCommand(): CommandModule {
101107
const output = await strings({
102108
path: argv.path as string,
103109
languages: argv.languages as string[] | undefined,
110+
missingLanguages: argv['missing-languages'] as string[] | undefined,
104111
keyFilter,
105112
textFilter,
106113
format: argv.format as string | undefined,
@@ -150,6 +157,7 @@ export async function strings(options: ListOptions): Promise<string> {
150157
const matchKey = buildMatcher(options.keyFilter);
151158
const matchText = buildMatcher(options.textFilter);
152159
const languageSet = options.languages ? new Set(options.languages) : null;
160+
const missingLanguageSet = options.missingLanguages ? new Set(options.missingLanguages) : null;
153161
const useTemplate = Boolean(options.format);
154162

155163
const lines: string[] = [];
@@ -161,6 +169,10 @@ export async function strings(options: ListOptions): Promise<string> {
161169
const localizations = unit?.localizations ?? {};
162170
const localizationKeys = Object.keys(localizations);
163171

172+
const isMissingSpecifiedLanguage = missingLanguageSet
173+
? Array.from(missingLanguageSet).some((lang) => !(lang in localizations))
174+
: true;
175+
164176
const perKeyLines: string[] = [];
165177

166178
for (const lang of localizationKeys) {
@@ -179,6 +191,10 @@ export async function strings(options: ListOptions): Promise<string> {
179191
continue;
180192
}
181193

194+
if (!isMissingSpecifiedLanguage) {
195+
continue;
196+
}
197+
182198
if (useTemplate) {
183199
lines.push(...perKeyLines);
184200
} else {

0 commit comments

Comments
 (0)