diff --git a/nodebb.bat b/nodebb.bat index d432dd3143..daaf09224f 100644 --- a/nodebb.bat +++ b/nodebb.bat @@ -1,122 +1 @@ -@echo off - -rem %1 action -rem %2 subaction - -setlocal enabledelayedexpansion -2>nul call :CASE_%1 -if ERRORLEVEL 1 call :DEFAULT_CASE - -exit /B - -:CASE_start - echo Starting NodeBB - echo "nodebb.bat stop" to stop the NodeBB server - echo "nodebb.bat log" to view server output - - rem Start the loader daemon - node loader %* - - goto END_CASE - -:CASE_stop - call :pidexists - if %_result%==0 ( - echo NodeBB is already stopped. - ) else ( - echo Stopping NodeBB. Goodbye! - - rem Doing this forcefully is probably not the best method - taskkill /PID !_pid! /f>nul - ) - - goto END_CASE - -:CASE_restart - echo Unsupported - - goto END_CASE - -:CASE_reload - echo Unsupported - - goto END_CASE - -:CASE_status - call :pidexists - if %_result%==0 ( - echo NodeBB is not running - echo "nodebb.bat start" to launch the NodeBB server - ) else ( - echo NodeBB Running ^(pid !_pid!^) - echo "nodebb.bat stop" to stop the NodeBB server - echo "nodebb.bat log" to view server output - echo "nodebb.bat restart" to restart NodeBB - ) - - goto END_CASE - -:CASE_log - cls - type .\logs\output.log - - goto END_CASE - -:CASE_upgrade - call npm install - call npm i nodebb-theme-vanilla nodebb-theme-lavender nodebb-widget-essentials - node app --upgrade - copy /b package.json +,,>nul - - goto END_CASE - -:CASE_setup - node app --setup %* - - goto END_CASE - -:CASE_reset - node app --reset --%2 - - goto END_CASE - -:CASE_dev - echo Launching NodeBB in "development" mode. - echo To run the production build of NodeBB, please use "forever". - echo More Information: https://docs.nodebb.org/en/latest/running/index.html - set NODE_ENV=development - node loader --no-daemon %* - - goto END_CASE - -:CASE_watch - echo Not supported - - goto END_CASE - -:DEFAULT_CASE - echo Welcome to NodeBB - echo Usage: nodebb.bat ^{start^|stop^|reload^|restart^|log^|setup^|reset^|upgrade^|dev^|watch^} - - goto END_CASE - -:END_CASE - endlocal - VER > NUL - goto :EOF - -:pidexists -if exist %~dp0pidfile ( - set /p _pid=Guest has posted a reply to: My Topic'); - done(); }); }); - it('should handle language keys inside language keys with all parameters as language keys', function (done) { + it('should handle language keys inside language keys with all parameters as language keys', function () { var translator = Translator.create('en-GB'); - translator.translate('[[notifications:user_posted_to, [[global:guest]], [[global:guest]]]]').then(function (translated) { + return translator.translate('[[notifications:user_posted_to, [[global:guest]], [[global:guest]]]]').then(function (translated) { assert.strictEqual(translated, 'Guest has posted a reply to: Guest'); - done(); }); }); - it('should properly handle parameters that contain square brackets', function (done) { + it('should properly handle parameters that contain square brackets', function () { var translator = Translator.create('en-GB'); - translator.translate('[[global:pagination.out_of, [guest], [[global:home]]]]').then(function (translated) { + return translator.translate('[[global:pagination.out_of, [guest], [[global:home]]]]').then(function (translated) { assert.strictEqual(translated, '[guest] out of Home'); - done(); }); }); - it('should properly handle parameters that contain parentheses', function (done) { + it('should properly handle parameters that contain parentheses', function () { var translator = Translator.create('en-GB'); - translator.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]').then(function (translated) { + return translator.translate('[[global:pagination.out_of, (foobar), [[global:home]]]]').then(function (translated) { assert.strictEqual(translated, '(foobar) out of Home'); - done(); }); }); - it('should not translate language key parameters with HTML in them', function (done) { + it('should escape language key parameters with HTML in them', function () { var translator = Translator.create('en-GB'); var key = '[[global:403.login, test]]'; - translator.translate(key).then(function (translated) { + return translator.translate(key).then(function (translated) { assert.strictEqual(translated, 'Perhaps you should try logging in?'); - done(); }); }); - it('should properly escape % and ,', function (done) { + it('should properly escape and ignore % and \\, in arguments', function () { var translator = Translator.create('en-GB'); - var title = 'Test 1, 2, 3 % salmon'; - title = title.replace(/%/g, '%').replace(/,/g, ','); + var title = 'Test 1\\, 2\\, 3 % salmon'; var key = "[[topic:composer.replying_to, " + title + "]]"; - translator.translate(key).then(function (translated) { - assert.strictEqual(translated, 'Replying to Test 1, 2, 3 % salmon'); - done(); + return translator.translate(key).then(function (translated) { + assert.strictEqual(translated, 'Replying to Test 1, 2, 3 % salmon'); }); }); - it('should not translate [[derp] some text', function (done) { + it('should not translate [[derp] some text', function () { var translator = Translator.create('en-GB'); - translator.translate('[[derp] some text').then(function (translated) { + return translator.translate('[[derp] some text').then(function (translated) { assert.strictEqual('[[derp] some text', translated); - done(); }); }); - it('should not translate [[derp:xyz] some text', function (done) { + it('should not translate [[derp:xyz] some text', function () { var translator = Translator.create('en-GB'); - translator.translate('[[derp:xyz] some text').then(function (translated) { + return translator.translate('[[derp:xyz] some text').then(function (translated) { assert.strictEqual('[[derp:xyz] some text', translated); - done(); }); }); - it('should translate [[pages:users/latest]] properly', function (done) { + it('should translate keys with slashes properly', function () { var translator = Translator.create('en-GB'); - translator.translate('[[pages:users/latest]]').then(function (translated) { + return translator.translate('[[pages:users/latest]]').then(function (translated) { assert.strictEqual(translated, 'Latest Users'); - done(); }); }); }); @@ -188,7 +171,7 @@ describe('Translator.create()', function () { }); describe('Translator modules', function () { - it('should work before registered', function (done) { + it('should work before registered', function () { var translator = Translator.create(); Translator.registerModule('test-custom-integer-format', function (lang) { @@ -207,20 +190,16 @@ describe('Translator modules', function () { }; }); - translator.translate('[[test-custom-integer-format:octal, 24]]') - .then(function (translation) { + return translator.translate('[[test-custom-integer-format:octal, 24]]').then(function (translation) { assert.strictEqual(translation, '30'); - done(); }); }); - it('should work after registered', function (done) { + it('should work after registered', function () { var translator = Translator.create('de'); - translator.translate('[[test-custom-integer-format:octal, 23]]') - .then(function (translation) { + return translator.translate('[[test-custom-integer-format:octal, 23]]').then(function (translation) { assert.strictEqual(translation, '27'); - done(); }); }); @@ -244,4 +223,41 @@ describe('Translator static methods', function () { done(); }); }); + describe('.escape', function () { + it('should escape translation patterns within text', function (done) { + assert.strictEqual( + Translator.escape('some nice text [[global:home]] here'), + 'some nice text \\[\\[global:home\\]\\] here' + ); + done(); + }); + }); + + describe('.unescape', function () { + it('should unescape escaped translation patterns within text', function (done) { + assert.strictEqual( + Translator.unescape('some nice text \\[\\[global:home\\]\\] here'), + 'some nice text [[global:home]] here' + ); + done(); + }); + }); + + describe('.compile', function () { + it('should create a translator pattern from a key and list of arguments', function (done) { + assert.strictEqual( + Translator.compile('amazing:cool', 'awesome', 'great'), + '[[amazing:cool, awesome, great]]' + ); + done(); + }); + + it('should escape `%` and `,` in arguments', function (done) { + assert.strictEqual( + Translator.compile('amazing:cool', '100% awesome!', 'one, two, and three'), + '[[amazing:cool, 100% awesome!, one, two, and three]]' + ); + done(); + }); + }); });