forked from AlchemyCMS/alchemy_cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Install webpacker and configure own instance Following the official webpacker engines guide * Add demo admin JS pack Something to work with during testing * Serve and compile Alchemy packs in host app Serve the Alchemy packs via Rack::Static if public file server is enabled (ie. during development) and enhance the yarn:install and assets:precompile tasks so that the Alchemy packs get compiled asd well. Copy over the files into host apps public/ folder afterwards. * Ensure that we run yarn install before installing Alchemy * Ensure to also serve packs in tests * Install node modules on GH CI * Do not use our own webpacker instance in page preview We want the webpacker instance of the host app in the preview frame. * Use webpacker 5 * Add a prettier config * Add a webpack-dev-server proxy * Only enhance rake tasks that are present If you install webpacker into a fresh Rails app there is not yarn:install task yet. * Update Babel config and add core-js * Add and configure Jest * Run Jest specs in GH CI * Convert i18n module into ES6 * Add favicon to assets Sprockets complains that we need this file * Enable Jest coverage reports for code climate * Ignore unknown window messages Now that we have Webpack installed the dev server emits messages on the window as well. Lets just ignore them.
- Loading branch information
Showing
32 changed files
with
691 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"semi": false, | ||
"trailingComma": "none", | ||
"vueIndentScriptAndStyle": true, | ||
"arrowParens": "always" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
app/assets/javascripts/alchemy/alchemy.translations.js.coffee
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import translate from "../i18n" | ||
|
||
describe("translate", () => { | ||
describe("if Alchemy.locale is not set", () => { | ||
it("Throws an error", () => { | ||
expect(() => { | ||
translate("help") | ||
}).toThrow("Alchemy.locale is not set") | ||
}) | ||
}) | ||
|
||
describe("if Alchemy.locale is set to a known locale", () => { | ||
beforeEach(() => { | ||
Alchemy.locale = "en" | ||
}) | ||
|
||
describe("if translation is present", () => { | ||
it("Returns translated string", () => { | ||
expect(translate("help")).toEqual("Help") | ||
}) | ||
|
||
describe("if key includes a period", () => { | ||
describe("that is translated", () => { | ||
it("splits into group", () => { | ||
expect(translate("formats.date")).toEqual("Y-m-d") | ||
}) | ||
}) | ||
|
||
describe("that is not translated", () => { | ||
it("returns key", () => { | ||
expect(translate("formats.lala")).toEqual("formats.lala") | ||
}) | ||
}) | ||
|
||
describe("that has unknown group", () => { | ||
it("returns key", () => { | ||
expect(translate("foo.bar")).toEqual("foo.bar") | ||
}) | ||
}) | ||
}) | ||
|
||
describe("if replacement is given", () => { | ||
it("replaces it", () => { | ||
expect(translate("allowed_chars", 5)).toEqual("of 5 chars") | ||
}) | ||
}) | ||
}) | ||
|
||
describe("if translation is not present", () => { | ||
it("Returns passed string", () => { | ||
expect(translate("foo")).toEqual("foo") | ||
}) | ||
}) | ||
}) | ||
|
||
describe("if Alchemy.locale is set to a unknown locale", () => { | ||
beforeEach(() => { | ||
Alchemy.locale = "kl" | ||
}) | ||
|
||
it("Returns passed string and logs a warning", () => { | ||
const spy = jest.spyOn(console, "warn").mockImplementation(() => {}) | ||
expect(translate("help")).toEqual("help") | ||
expect(spy.mock.calls).toEqual([ | ||
["Translations for locale kl not found!"] | ||
]) | ||
spy.mockRestore() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import translationData from "./translations" | ||
|
||
const KEY_SEPARATOR = /\./ | ||
|
||
function currentLocale() { | ||
if (Alchemy.locale == null) { | ||
throw "Alchemy.locale is not set! Please set Alchemy.locale to a locale string in order to translate something." | ||
} | ||
return Alchemy.locale | ||
} | ||
|
||
function getTranslations() { | ||
const locale = currentLocale() | ||
const translations = translationData[locale] | ||
|
||
if (translations) { | ||
return translations | ||
} | ||
console.warn(`Translations for locale ${locale} not found!`) | ||
return {} | ||
} | ||
|
||
function nestedTranslation(translations, key) { | ||
const keys = key.split(KEY_SEPARATOR) | ||
const group = translations[keys[0]] | ||
if (group) { | ||
return group[keys[1]] || key | ||
} | ||
return key | ||
} | ||
|
||
function getTranslation(key) { | ||
const translations = getTranslations() | ||
|
||
if (KEY_SEPARATOR.test(key)) { | ||
return nestedTranslation(translations, key) | ||
} | ||
return translations[key] || key | ||
} | ||
|
||
export default function translate(key, replacement) { | ||
let translation = getTranslation(key) | ||
|
||
if (replacement) { | ||
return translation.replace(/%\{.+\}/, replacement) | ||
} | ||
return translation | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const translations = { | ||
en: { | ||
allowed_chars: "of %{count} chars", | ||
cancel: "Cancel", | ||
cancelled: "Cancelled", | ||
click_to_edit: "click to edit", | ||
complete: "Complete", | ||
element_dirty_notice: | ||
"This element has unsaved changes. Do you really want to fold it?", | ||
help: "Help", | ||
ok: "Ok", | ||
page_dirty_notice: | ||
"You have unsaved changes on this page. They will be lost if you continue.", | ||
page_found: "Page found", | ||
pages_found: "Pages found", | ||
url_validation_failed: "The url has no valid format.", | ||
warning: "Warning!", | ||
"File is too large": "File is too large", | ||
"File is too small": "File is too small", | ||
"File type not allowed": "File type not allowed", | ||
"Maximum number of files exceeded": "Maximum number of files exceeded.", | ||
"Uploaded bytes exceed file size": "Uploaded bytes exceed file size", | ||
formats: { | ||
datetime: "Y-m-d H:i", | ||
date: "Y-m-d", | ||
time: "H:i", | ||
time_24hr: false | ||
} | ||
} | ||
} | ||
|
||
export default translations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import translate from "alchemy/admin/i18n" | ||
|
||
// Global Alchemy object | ||
if (typeof window.Alchemy === "undefined") { | ||
window.Alchemy = {} | ||
} | ||
|
||
// Global utility method for translating a given string | ||
// | ||
Alchemy.t = (key, replacement) => { | ||
return translate(key, replacement) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.