Skip to content

Commit

Permalink
Generate source file without leading slash
Browse files Browse the repository at this point in the history
Our code to write translations back to disk when we create pull requests
does not handle leading slahses well and anyway, the sourceFile is meant
to be relative, not absolute.
  • Loading branch information
WULCAN committed Nov 24, 2024
1 parent 2fd47fa commit 5fc0f83
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 31 additions & 0 deletions webapp/src/store/ProjectStore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,37 @@ describe('ProjectStore', () => {
});
});

describe('updateTranslation', () => {
it('does not prefix source file with /', async () => {
const store = new ProjectStore(
{
getMessages: async () => [
{
defaultMessage: 'Click',
id: 'core.click',
params: [],
},
],
},
{
getTranslations: async () => ({
en: {
'core.click': {
sourceFile: 'en.yml',
text: 'Click',
},
},
}),
},
);

await store.updateTranslation('sv', 'core.click', 'Klicka');

const actual = await store.getTranslations('sv');
expect(actual['core.click'].sourceFile).toEqual('sv.yml');
});
});

it('gives full access to all languages', async () => {
const msgAdapter = mockMsgAdapter();
msgAdapter.getMessages.mockResolvedValue([
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/store/ProjectStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class ProjectStore {
/^en\.(.+\.)*(ya?ml)$/g,
`${lang}.$1$2`,
);
return enSourceFileArr.join('/').concat(`/${langFileName}`);
enSourceFileArr.push(langFileName);
return enSourceFileArr.join('/');
}
}

0 comments on commit 5fc0f83

Please sign in to comment.