Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/large-bees-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@replexica/spec": minor
"@replexica/cli": minor
"replexica": minor
---

Added support for .properties file
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"open": "^10.1.0",
"ora": "^8.0.1",
"p-limit": "^6.1.0",
"properties-parser": "^0.6.0",
"slugify": "^1.6.6",
"typescript": "^5.4.5",
"vitest": "^2.0.0",
Expand All @@ -53,6 +54,7 @@
"@types/markdown-it": "^14.1.2",
"@types/node": "^20.14.10",
"@types/object-hash": "^3.0.6",
"@types/properties-parser": "^0.3.3",
"@types/xml2js": "^0.4.14",
"tsup": "^8.1.0"
}
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/workers/bucket/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { rootKeyLoader } from './root-key';
import { markdownLoader } from './markdown';
import { xcodeLoader } from './xcode';
import { androidLoader } from './android';
import { propertiesLoader } from './properties';

// Path expansion
export function expandPlaceholderedGlob(pathPattern: string, sourceLocale: string): string[] {
Expand Down Expand Up @@ -126,5 +127,11 @@ export function createBucketLoader(params: CreateBucketLoaderParams) {
jsonLoader(),
flatLoader(),
);
case 'properties':
return composeLoaders<string, Record<string, string>>(
textLoader(filepath),
propertiesLoader(),
flatLoader(),
);
}
}
46 changes: 46 additions & 0 deletions packages/cli/src/workers/bucket/v2/properties.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { describe, it, expect } from 'vitest';
import { propertiesLoader } from './properties'; // Adjust the import path as needed

describe('propertiesLoader', () => {
const loader = propertiesLoader();

const sampleProperties = `
# General messages
welcome.message=Welcome to our application!
error.message=An error has occurred. Please try again later.

# User-related messages
user.login=Please enter your username and password.
user.username=Username
user.password=Password
`.trim();

it('should load properties correctly', async () => {
const result = await loader.load(sampleProperties);
expect(result).toEqual({
'welcome.message': 'Welcome to our application!',
'error.message': 'An error has occurred. Please try again later.',
'user.login': 'Please enter your username and password.',
'user.username': 'Username',
'user.password': 'Password'
});
});

it('should save properties correctly', async () => {
const input = {
'app.name': 'My App',
'app.version': '1.0.0',
'user.greeting': 'Hello, {0}!'
};

const result = await loader.save(input);
expect(result).toContain('app.name=My App');
expect(result).toContain('app.version=1.0.0');
expect(result).toContain('user.greeting=Hello, {0}!');
});

it('should handle empty input when loading', async () => {
const result = await loader.load('');
expect(result).toEqual({});
});
});
18 changes: 18 additions & 0 deletions packages/cli/src/workers/bucket/v2/properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { parse, createEditor } from 'properties-parser';
import { BucketLoader } from './_base';

export const propertiesLoader = (): BucketLoader<string, Record<string, string>> => ({
async load(text: string) {
return parse(text || '');
},
async save(payload) {
const editor = createEditor();

// Update or add new key-value pairs
for (const [key, value] of Object.entries(payload)) {
editor.set(key, value);
}

return editor.toString();
}
});
1 change: 1 addition & 0 deletions packages/spec/src/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const bucketTypes = [
'yaml-root-key',
'xcode',
'android',
'properties',
] as const;

export const bucketTypeSchema = Z.enum(bucketTypes);
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.