2.0.29 • Published 3 months ago

senselogic-gist v2.0.29

Weekly downloads
-
License
LGPL-3.0-only
Repository
github
Last release
3 months ago

npm.io

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.

2.0.29

3 months ago

2.0.28

5 months ago

2.0.26

5 months ago

2.0.27

5 months ago

2.0.25

5 months ago

2.0.24

5 months ago

2.0.23

5 months ago

2.0.22

5 months ago

2.0.21

5 months ago

2.0.20

5 months ago

2.0.19

5 months ago

2.0.18

5 months ago

2.0.7

8 months ago

2.0.6

8 months ago

2.0.9

7 months ago

2.0.8

8 months ago

2.0.15

7 months ago

2.0.16

7 months ago

2.0.13

7 months ago

2.0.14

7 months ago

2.0.11

7 months ago

2.0.12

7 months ago

2.0.10

7 months ago

2.0.17

7 months ago

1.0.1

8 months ago

1.0.0

8 months ago

2.0.3

8 months ago

2.0.2

8 months ago

2.0.5

8 months ago

2.0.4

8 months ago

2.0.1

8 months ago

2.0.0

8 months ago

0.1.41

10 months ago

0.1.42

10 months ago

0.1.43

10 months ago

0.1.44

9 months ago

0.1.45

9 months ago

0.1.46

9 months ago

0.1.47

9 months ago

0.1.40

10 months ago

0.1.38

11 months ago

0.1.39

11 months ago

0.1.30

11 months ago

0.1.31

11 months ago

0.1.32

11 months ago

0.1.33

11 months ago

0.1.34

11 months ago

0.1.35

11 months ago

0.1.36

11 months ago

0.1.37

11 months ago

0.1.27

12 months ago

0.1.28

11 months ago

0.1.29

11 months ago

0.1.25

1 year ago

0.1.26

1 year ago

0.1.22

2 years ago

0.1.23

2 years ago

0.1.24

1 year ago

0.1.20

2 years ago

0.1.21

2 years ago

0.1.10

2 years ago

0.1.11

2 years ago

0.1.12

2 years ago

0.1.13

2 years ago

0.1.14

2 years ago

0.1.15

2 years ago

0.1.16

2 years ago

0.1.8

2 years ago

0.1.17

2 years ago

0.1.7

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.9

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago