Options
Modules
  • Command
  • Localization
  • Logger
All
  • Public
  • Public/Protected
  • All
Menu

@discord-samba/localization

Index

Type aliases

CommandInfoProvider

CommandInfoProvider: (language: string, command: string, prefix: string) => { desc?: string; help?: string; usage?: string }

Represents a function that can provide information about the given command in the given language. Accepts a prefix to pass to the localization resources that will be loaded

Type declaration

    • (language: string, command: string, prefix: string): { desc?: string; help?: string; usage?: string }
    • Parameters

      • language: string
      • command: string
      • prefix: string

      Returns { desc?: string; help?: string; usage?: string }

      • Optional desc?: string
      • Optional help?: string
      • Optional usage?: string

LocalizationPipeFunction

LocalizationPipeFunction: (pipeValue: any, ...args: any[]) => any

Represents a function that can be used in Localization files by piping template values into it. The function must accept the piped-in template value, and can optionally accept any other static values of the types string, number, or boolean. These additional values allow pipe functions to be configurable.

Note: The typings specify any type for these additional parameters, but the localization parser only supports string, number, and boolean primitives in the localization file syntax, which translate directly to their JavaScript equivalents

In the case of regular templates and optional templates, the piped-in value is of whatever type the template argument value is. In the case of include templates the piped-in value is always a string, given that the value is an included resource which is a fully-built localization string

Realistically pipe functions can transform the piped in data in many ways and can accept piped-in data of any type, given anything can be passed to Localization resources as desired. However, you should always make sure to be aware of how each function is transforming your data with regards to what is being piped into the next.

Type declaration

    • (pipeValue: any, ...args: any[]): any
    • Parameters

      • pipeValue: any
      • Rest ...args: any[]

      Returns any

LocalizationResourceProxy

LocalizationResourceProxy<T>: {[ K in keyof T]: T[K] extends Record<string, never> ? (args?: T[K] & Record<string, any>) => string : (args: T[K] & Record<string, any>) => string } & {}

Represents a Proxy object for a specific language where function calls will call Localization.resource() for that language and forward the given TemplateArguments to the resource lookup.

TypeScript note: Can be given a type parameter object where the keys are Localization string keys mapped to type objects that map template keys to template value types. This will provide type hinting for both template key names (methods on the proxy) and the template arguments they expect. Example:

type Resources = { foo: { bar: string, baz?: number } };
const proxy: LocalizationResourceProxy<Resources> = Localization.getResourceProxy('en-US');
const foo: string = proxy.foo({ bar: 'baz' });
// The compiler knows that the value of `bar` should be a string, and
// that `baz` expects a number but is optional

Type parameters

  • T: {} = {}

ResourcePath

ResourcePath: string | [string] | [string, string] | [string, string, string]

Represents a language identifier (string) or tuple of string identifiers that lead to a distinct set of localization resources. The value will be interpreted as follows:

[language, category, subcategory] // Self-explanatory
[language, category]              // Defaults to 'default' subcategory
[language]                        // Defaults to 'default' category, 'default' subcategory
'language'                        // Defaults to 'default' category, 'default' subcategory

Functions

Const commandInfoProvider

  • commandInfoProvider(language: string, command: string, prefix: string): { desc?: string; help?: string; usage?: string }
  • CommandInfoProvider function that can provide localized command info for the given command in the given language if it exists

    Parameters

    • language: string
    • command: string
    • prefix: string

    Returns { desc?: string; help?: string; usage?: string }

    • Optional desc?: string
    • Optional help?: string
    • Optional usage?: string

Generated using TypeDoc