bitjson / s18n

Semantic localization for html.
MIT License
23 stars 10 forks source link

Added sort option to disable the extract locales sort #37

Open Lukas238 opened 3 years ago

Lukas238 commented 3 years ago

This pull request just add a new boolean option sort.

var opts = {
    native: 'english',
    elements: [],
    attributes: ['alt', 'title', 'placeholder'],
    sort: false
};

s18n.extractFiles(file, opts)
    .then(function(locale) {
        console.log(locale);
    });

The default value of the option is true, witch keep the plugin original behavior unchanged.

Declaring the option sort to false will just disable the sorting algorithm on lib/formatLocale.js script.

Use case

The objective of this changes, is to be able to extract native locales from an HTML page, and keep the same order, as in the source page.

This make it easy for sending the locale files for translation to a different developing team. As they will need to visually match the original copy with the source page.

Best regards!

Lukas238 commented 3 years ago

Hi,

I'm trying to make a correct pull request, but I get this travis-ci/pr fail error every time I commit.

Running 'gulp test` command on my local machine show no errors at all.

So, not sure what to do next.

Any help will be much appreciated. :)

  dassol@buewcjdassomac s18n % gulp test
[13:25:03] Using gulpfile ~/Work/s18n/gulpfile.js
[13:25:03] Starting 'jscs-jshint'...
[13:25:04] Finished 'jscs-jshint' after 1.08 s
[13:25:04] Starting 'test'...
[13:25:04] Starting 'rm-coverage'...
[13:25:04] Finished 'test' after 24 ms
[13:25:04] Finished 'rm-coverage' after 34 ms
[13:25:04] Starting 'cover-tests'...

  CLI: 's18n extract'
    ✓ should extract from fixtures using defaults (532ms)
    ✓ should '$ s18n extract -s "<p>Hello, World!</p>"' (334ms)
    ✓ should '$ s18n extract -p '["**/*.html", "!**/b.html", "!*/sample/**/*.html"]' (367ms)
    ✓ should '$ s18n extract -a . -e . -d s18n' (374ms)

  CLI: 's18n'
    ✓ should return usage when no command is provided (201ms)
    ✓ should return the current version (189ms)

  CLI: 's18n localize'
    ✓ should localize without args (using defaults) (357ms)

  CLI: 's18n map'
    ✓ should map the fixture locale using defaults (575ms)

  s18n.compareLocales()
    ✓ should be a method
    ✓ should error if either locale is not an object
    ✓ should return a locale comparison array

  s18n.extract()
    ✓ should be a method
    ✓ should extract locale strings from configured html elements (42ms)
    ✓ should trimWhitespace from strings by default
    ✓ should leave surrounding whitespace when trimWhitespace is false
    ✓ should not include empty strings in extracted locale
    ✓ should extract locale strings from configured html attributes
    ✓ should extract locale strings from html elements with configured directives
    ✓ should not extract locale strings from html elements with configured cancelers
    ✓ should extract locale strings from attributes provided to the attributeSetter
    ✓ should not extract locale strings from attributes provided to the attributeCanceler
    ✓ should not extract locale strings from withing excluded elements
    ✓ should allow other hash algorithms
    ✓ should allow for different hash lengths
    ✓ should return an alphabetically sorted locale object
    ✓ should return an unsorted locale object

  s18n.extractFiles()
    ✓ should be a method
    ✓ should extract locale strings from a file
    ✓ should extract locale strings from multiple files
    ✓ should accept globbyOpts
    ✓ should return an alphabetically sorted locale object
    ✓ should reject on errors

  s18n.formatLocale()
    ✓ should be a method
    ✓ should sort and return a locale as a string
    ✓ should sort and return a locale as an object
    ✓ should return an unsorted locale as a string
    ✓ should return an unsorted locale as an object
    ✓ should throw an error if output option is unrecognized

  s18n()
    ✓ should be a method
    ✓ should throw an error if `nativeLocale` option is undefined
    ✓ should throw an error if `locales` option is undefined
    ✓ should throw an error if `rewriteLangAttribute` is true and `nativeLocaleId` is not set
    ✓ should throw an error if `rewriteLangAttribute` is true and the `locale` option is used without `localeId` set
    ✓ should localize some html
    ✓ should localize some html with only one locale
    ✓ should rewrite `lang` attributes
    ✓ should output the proper `lang` value when `s18n-lock-lang` is encountered
    ✓ should error if both `locale` and `locales` are set
    ✓ should localize strings only in localizable places (/>*</, /"*"/, /'*'/)
    ✓ should preserve and ignore insignificant whitespace when localizing
    ✓ should localize the longest match when multiple locale strings match
    ✓ should ignore empty attributes in the native locale (output by htmlparser2)
    ✓ should match extra spaces not in the native locale (due to htmlparser2-cleaned output)
    ✓ should localize some html with multiple locales

  s18n.map()
    ✓ should be a method
    ✓ should replace substrings using a provided dictionary
    ✓ should replace substrings properly
    ✓ should default to the `accents` dictionary
    ✓ should accept the `accents` dictionary
    ✓ should not replace characters within html tags
    ✓ should not replace characters within html entites

  61 passing (3s)

=============================================================================
Writing coverage object [/Users/dassol/Work/s18n/coverage/coverage.json]
Writing coverage reports at [/Users/dassol/Work/s18n/coverage]
=============================================================================
--------------------|----------|----------|----------|----------|----------------|
File                |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
--------------------|----------|----------|----------|----------|----------------|
 lib/               |      100 |      100 |      100 |      100 |                |
  compareLocales.js |      100 |      100 |      100 |      100 |                |
  extract.js        |      100 |      100 |      100 |      100 |                |
  extractFiles.js   |      100 |      100 |      100 |      100 |                |
  formatLocale.js   |      100 |      100 |      100 |      100 |                |
  localize.js       |      100 |      100 |      100 |      100 |                |
  map.js            |      100 |      100 |      100 |      100 |                |
  s18n.js           |      100 |      100 |      100 |      100 |                |
  utils.js          |      100 |      100 |      100 |      100 |                |
--------------------|----------|----------|----------|----------|----------------|
All files           |      100 |      100 |      100 |      100 |                |
--------------------|----------|----------|----------|----------|----------------|

[13:25:08] Finished 'cover-tests' after 3.78 s
[13:25:08] Starting 'enforce-coverage'...
[13:25:08] Finished 'enforce-coverage' after 178 ms
dassol@buewcjdassomac s18n % 

Best regards!