🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

senselogic-gist

Package Overview
Dependencies
Maintainers
0
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

senselogic-gist

Reusable base functions.

3.0.8
latest
Source
npm
Version published
Weekly downloads
84
147.06%
Maintainers
0
Weekly downloads
 
Created
Source

Gist

Reusable base functions.

Features

  • logging
  • math
  • string
  • base64
  • UUID
  • random
  • time
  • date
  • path
  • continent
  • country
  • location
  • localization
  • processing
  • tracking

Internationalization

Any string can be internationalized by providing additional translations after an umlaut character followed by a language specifier.

Translations are tested from right to left, the first translation being used by default.

A language specifier can contain one or several language tags separated by commas.

A language tag can define a language code, a country code and a continent code, separated by dashes.

multilingualText = 'trunk¨en-UK,en--OC:boot¨fr:coffre¨pt:mala¨pt-BR:porta-malas';

setLanguageCode( 'en' );
setCountryCode( 'US' );
assert( getLocalizedText( multilingualText ) === 'trunk' );

setLanguageCode( 'en' );
setCountryCode( 'UK' );
assert( getLocalizedText( multilingualText ) === 'boot' );

setLanguageCode( 'en' );
setCountryCode( 'AU' );
assert( getLocalizedText( multilingualText ) === 'boot' );

setLanguageCode( 'fr' );
setCountryCode( 'FR' );
assert( getLocalizedText( multilingualText ) === 'coffre' );

setLanguageCode( 'pt' );
setCountryCode( 'PT' );
assert( getLocalizedText( multilingualText ) === 'mala' );

setLanguageCode( 'pt' );
setCountryCode( 'BR' );
assert( getLocalizedText( multilingualText ) === 'porta-malas' );

Translations can also include variables, and use them to define additional conditions.

multilingualText = '{count} bathrooms¨en?count=1:{count} bathroom¨fr:{count} salles de bain¨fr?count<2:{count} salle de bain';

setLanguageCode( 'en' );
setCountryCode( 'US' );
assert( getLocalizedText( multilingualText, { count: 0 } ) === '0 bathrooms' );
assert( getLocalizedText( multilingualText, { count: 1 } ) === '1 bathroom' );
assert( getLocalizedText( multilingualText, { count: 2 } ) === '2 bathrooms' );

setLanguageCode( 'fr' );
setCountryCode( 'FR' );
assert( getLocalizedText( multilingualText, { count: 0 } ) === '0 salle de bain' );
assert( getLocalizedText( multilingualText, { count: 1 } ) === '1 salle de bain' );
assert( getLocalizedText( multilingualText, { count: 2 } ) === '2 salles de bain' );

Translations can contain tags and entities :

A text<br>on two lines.¨fr:Un texte<br>sur deux lignes.

They can also contain custom tags :

A **bold** text§on two lines.¨fr:Un texte en **gras**§sur deux lignes.

Custom tags can be freely defined :

defineTag( '§', '<br/>' );
defineDualTag( '**', '<b>', '</b>' );

Version

2.0

Author

Eric Pelzer (ecstatic.coder@gmail.com).

License

This project is licensed under the GNU Lesser General Public License version 3.

See the LICENSE.md file for details.

Keywords

gist

FAQs

Package last updated on 10 Nov 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