Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add TypeScript declarations for translate functions #756

Merged
merged 1 commit into from Mar 7, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/i18n/translate/translate.d.ts
@@ -0,0 +1,5 @@
export type Replacements = {
[key: string]: string;
};

export type TranslateFunction = (template: string, replacements?: Replacements) => string;
6 changes: 5 additions & 1 deletion lib/i18n/translate/translate.js
@@ -1,3 +1,7 @@
/**
* @typedef {import('./').Replacements} Replacements
*/

/**
* A simple translation stub to be used for multi-language support
* in diagrams. Can be easily replaced with a more sophisticated
Expand All @@ -12,7 +16,7 @@
* }
*
* @param {string} template to interpolate
* @param {Object} [replacements] a map with substitutes
* @param {Replacements} [replacements] a map with substitutes
*
* @return {string} the translated string
*/
Expand Down
11 changes: 11 additions & 0 deletions lib/i18n/translate/translate.spec.ts
@@ -0,0 +1,11 @@
import { TranslateFunction } from './translate';

const translate: TranslateFunction = (template, replacements) => {
for (let replacement in replacements) {
console.log(replacement, replacements[ replacement ]);
}

return template;
};

translate('foo {{bar}}', { bar: 'baz' });