Skip to content

Commit

Permalink
feat: create a method to get a translate method with bound context
Browse files Browse the repository at this point in the history
  • Loading branch information
IamSebastianDev committed Apr 29, 2023
1 parent 068cc8c commit 5a48cc0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib/Vay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,16 @@ export class Vay<T extends Dictionary<Record<string, Phrase>>> {
this._processAttributes(element);
});
}

/**
* @description
* Creates a new translator function bound to the current Vay instance. The returned function
* can be used to translate tokens outside of the Vay instance.
*
* @returns {(token: PropertyPath<T['phrases']>, tData?: TranslationData, language?: ISO639Code) => string} A translator function
*/

createTranslator(): (token: PropertyPath<T['phrases']>, tData?: TranslationData, language?: ISO639Code) => string {
return this.translate.bind(this);
}
}

0 comments on commit 5a48cc0

Please sign in to comment.