Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nextcloud/l10n

Package Overview
Dependencies
Maintainers
13
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nextcloud/l10n

Nextcloud L10n helpers for apps and libraries

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
increased by1.75%
Maintainers
13
Weekly downloads
 
Created
Source

@nextcloud/l10n

Build Status npm Documentation

Nextcloud L10n helpers for apps and libraries.

Installation

npm i -S @nextcloud/l10n

Usage

OC.L10n abstraction

You can use helpers in this package in order generate code that also works when it's not loaded on a Nextcloud page. This is primary useful for testing. The logic will just return the original string if the global variable OC isn't found.

In order to not break the l10n string extraction scripts, make sure to alias the imported function to match the legacy syntax:

import { t, n } from '@nextcloud/l10n'
// Or
import { translate as t, translatePlural as n } from '@nextcloud/l10n'

t('myapp', 'Hello!')
n('myapp', '%n cloud', '%n clouds', 100)

See the localization docs for more info.

Independent translation

You can use this package to translate your app or library independent of Nextcloud. For that you need .po(t) files. These can be extracted with gettext-extractor.

import { getGettextBuilder } from '@nextcloud/l10n/gettext'

const lang = 'sv'
const po = ... // Use https://github.com/smhg/gettext-parser to read and convert your .po(t) file

const gt = getGettextBuilder()
    .detectLocale()
    .addTranslation('sv', po)
    .build()
Translate single string
gt.gettext('my source string')
Placeholders
gt.gettext('this is a {placeholder}. and this is {key2}', {
    placeholder: 'test',
    key2: 'also a test',
})

See the developer docs for general guidelines.

Translate plurals
gt.ngettext('%n Mississippi', '%n Mississippi', 3)

See the developer docs for general guidelines.

Keywords

FAQs

Package last updated on 06 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc