Translations is a class that provides internationalization (i18n) support for applications.

Translations 是一个为应用程序提供国际化 (i18n) 支持的类。

层级 (查看完整内容)

属性

_id: number = 0
destroyedImmediately: boolean

Whether to delete the resource immediately when the reference count is 0.

是否在引用计数为0的时候立马删除他

lock?: boolean

Whether to lock the resource, if true, the resource cannot be automatically released.

是否加锁,如果true为不能使用自动释放机制。

name?: string

The name of the resource.

资源名称。

url: string

The URL of the resource.

获取资源的URL地址。

uuid: string

The UUID of the resource.

获取资源的UUID。

DEBUG: boolean = false

Whether the debug mode is enabled.

是否开启调试模式。

provider: i18n = ...

获取或设置当前的国际化提供者。默认是一个简单的实现,如果需要高级功能,可以安装i18next,并设置到此属性。

Gets or sets the current i18n provider. The default is a simple implementation. If you need advanced features, you can install i18next and set it to this property.

import i18next from "i18next";

await i18next.init({...});

Laya.Translations.provider = i18next;

访问器

  • get obsolute(): boolean
  • 返回 boolean

    If a cached resource observer is set to true, then:

      1. getRes will still return this resource;
      1. next time loading will ignore this cached resource and reload it.

    如果设置一个已缓存的资源obsolute为true,则

    • 1)getRes仍然可以返回这个资源;
    • 2)下次加载时会忽略这个缓存而去重新加载。。
  • set obsolute(value): void
  • 参数

    • value: boolean

    返回 void

方法

  • 参数

    • count: number = 1

      The amount by which to increment the reference count, default is 1.

    返回 void

    Increments the reference count of the resource by the specified amount.

    按指定数量增加资源的引用计数。

  • 参数

    • count: number = 1

      The amount by which to decrement the reference count, default is 1.

    返回 void

    Decrements the reference count of the resource by the specified amount. If the reference count reaches zero and certain conditions are met, the resource may be destroyed.

    按指定数量减少资源的引用计数。如果引用计数达到零并且满足特定条件,资源可能会被销毁。

  • 参数

    • url: string

      The URL used to create the resource.

    • 可选uuid: string

      The optional UUID of the resource.

    返回 void

    Sets the URL and UUID used to create this resource.

    设置用于创建此资源的 URL 和 UUID。

  • 参数

    • type: string

      The type of event.

    • 可选data: any

      (Optional) Data to pass to the callback. If multiple parameters p1, p2, p3, ... need to be passed, use an array structure such as [p1, p2, p3, ...]. If a single parameter p needs to be passed and p is an array, use a structure such as [p]. For other single parameters p, you can directly pass parameter p. If data is Event.EMPTY, it means passing an Event object to the callback function. Note that it is not passing Event.TEMP, but an independent Event object.

    返回 boolean

    True if there are listeners for this event type, false otherwise.

    Dispatch an event.

    派发事件。

  • 参数

    • type: string

      The type of event.

    返回 boolean

    True if a listener of the specified type is registered, false otherwise.

    Check if the EventDispatcher object has any listeners registered for a specific type of event.

    检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。

  • 参数

    • url: string

      The URL to check against the resource's creation URL.

    返回 boolean

    True if the resource is created from the specified URL, otherwise false.

    Checks if the resource is created from the specified URL.

    检查资源是否从指定的 URL 创建。

  • 参数

    • 可选type: string

      (Optional) The type of event. If the value is null, all types of listeners on this object are removed.

    返回 EventDispatcher

    This EventDispatcher object.

    Remove all listeners of the specified event type from the EventDispatcher object.

    从 EventDispatcher 对象中删除指定事件类型的所有侦听器。

  • 参数

    • type: string

      The type of event.

    • listener: Function

      The listener function.

    返回 EventDispatcher

    This EventDispatcher object.

    Register an event listener object with the EventDispatcher object so that the listener receives event notifications.

    使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知。

  • 参数

    • type: string

      The type of event.

    • caller: any

      The execution scope of the event listener function.

    • listener: Function

      The listener function.

    • 可选args: any[]

      (Optional) The callback parameters of the event listener function.

    返回 EventDispatcher

    This EventDispatcher object.

    Register an event listener object with the EventDispatcher object so that the listener receives event notifications.

    使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知。

  • 参数

    • type: string

      The type of event.

    • listener: Function

      The listener function.

    返回 EventDispatcher

    This EventDispatcher object.

    Register an event listener object with the EventDispatcher object so that the listener receives event notifications. This event listener responds once and is automatically removed after the first call.

    使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知,此侦听事件响应一次后自动移除。

  • 参数

    • type: string

      The type of event.

    • caller: any

      The execution scope of the event listener function.

    • listener: Function

      The listener function.

    • 可选args: any[]

      (Optional) The callback parameters of the event listener function.

    返回 EventDispatcher

    This EventDispatcher object.

    Register an event listener object with the EventDispatcher object so that the listener receives event notifications. This event listener responds once and is automatically removed after the first call.

    使用 EventDispatcher 对象注册指定类型的事件侦听器对象,以使侦听器能够接收事件通知,此侦听事件响应一次后自动移除。

  • 参数

    • lng: string

      The language code for which the content is being set. If not provided, the current language of the i18n provider will be used.

    • content: any

      The content to set for the specified language, which should be an object containing key-value pairs for translations.

    返回 this

    The Translations instance itself for method chaining.

    Sets the content for a specific language in this Translations instance.

    为此 Translations 实例设置特定语言的内容。

  • 参数

    • name: string

      The name of the translation key to look up. It can be a simple key or a namespaced key in the format "namespace:key".

    • 可选defaultValue: string

      Optional default value to return if the translation key is not found. If provided, it will be returned as a fallback.

    返回 string

    The translated string. If the translation key is not found, the default value will be returned if provided, otherwise the key itself will be returned.

    Translates the given name using the current language and options.

    使用当前语言和选项翻译给定的名称。

  • 参数

    • name: string

      The name of the translation key to look up. It can be a simple key or a namespaced key in the format "namespace:key".

    • options: Record<string, any>

      Optional parameters for translation, such as variables to replace in the text.

    返回 string

    The translated string. If the translation key is not found, the default value will be returned if provided, otherwise the key itself will be returned.

    Translates the given name using the current language and options.

    使用当前语言和选项翻译给定的名称。

  • 参数

    • name: string

      The name of the translation key to look up. It can be a simple key or a namespaced key in the format "namespace:key".

    • defaultValue: string

      Optional default value to return if the translation key is not found. If provided, it will be returned as a fallback.

    • options: Record<string, any>

      Optional parameters for translation, such as variables to replace in the text.

    返回 string

    The translated string. If the translation key is not found, the default value will be returned if provided, otherwise the key itself will be returned.

    Translates the given name using the current language and options.

    使用当前语言和选项翻译给定的名称。

  • 参数

    • id: string

      The ID for the new Translations instance.

    • 可选fallbackLng: string

      The fallback language to use if the specified language is not available.

    返回 Translations

    A new Translations instance.

    Creates a new Translations instance with the specified ID and optional fallback language.

    创建一个新的 Translations 实例,指定 ID 和可选的回退语言。

  • 参数

    • text: string

      The i18n text string to decode, which should be in the format "i18n:sid:key|text" or "i18n:key|text".

    • 可选out: I18nTextInfo

      Optional output object to store the decoded information. If not provided, a new object will be created.

    返回 I18nTextInfo

    An object containing the decoded information, with properties sid, key, and text.

    Decodes an i18n text string into its components.

    将 i18n 文本字符串解码为其组件。

  • 参数

    • info: I18nTextInfo

      The i18n text information object containing sid, key, and text properties.

    • 可选newText: string

      Optional new text to replace the existing text in the i18n text object. If not provided, the existing text will be used.

    返回 string

    A string in the format "i18n:sid:key|text" or "i18n:key|text", depending on whether sid is present.

    Encodes an i18n text object into a string.

    将 i18n 文本对象编码为字符串。

  • 参数

    • text: string

      The text to translate, which can be in the format "i18n:sid:key|text" or "i18n:key|text".

    • 可选options: Record<string, any>

      Optional parameters for translation, such as variables to replace in the text.

    返回 string

    The translated text.

    Translates the given text.

    翻译给定的文本。