-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX JENKINS-39225] Internationalisation for Blue Ocean and JDL (#556)
* [JENKINS-35845] WIP first steps with i18n * eslint - formating changes and fix offences * [JENKINS-35845] first basic working version with 2 languages * [JENKINS-35845] WIP adding patched backend to investigate * [JENKINS-35845] Assumes jenkinsci/jenkins#2586 to be applied. We know get the translations from the standard jenkins way, but needs changes in the core for now * [JENKINS-35845] remove testing class * [JENKINS-35845] WIP fixing integration of jenkins i18n keys with dot in them * [JENKINS-35845] move i18n to core-js and using it from within web * [JENKINS-35845] follow jenkins convention/pattern for storing locale * [JENKINS-35845] WIP implement translation in core-js runbutton and toastUtil. Prefix translations with bo.web. remove sample code * [JENKINS-35845] WIP starting to translate dashboard * [JENKINS-35845] WIP added german translation and finished dashboard. Currently working on making moment respect the locale * [JENKINS-35845] Use latest jdl * [JENKINS-35845] fix locale retrieval * [JENKINS-35845] update stories to use the new i18n functions. Create story to test readableDate and timeDuration. In node this works fine now traking down wht not in dashboard * [JENKINS-35845] Add spanish translations * [JENKINS-35845] better translation for spanish (thank you @Dario) as well updated some german translations * [JENKINS-35845] Fix german translations with feedback from @daniel * [JENKINS-35845] Fix test view and finish translation * [JENKINS-35845] Fix german translation. fix result views. fix some lint issues. * [JENKINS-35845] create a compose function to wire different functions together * [JENKINS-35845] better documentation and remove debug string * [JENKINS-35845] add documentation about i18n and linking contributing and i18n docu in principal readme. * [JENKINS-35845] updte docu * [JENKINS-35845] Pass locale and translation function down the component tree. Fix links to not drop query parameters. * [JENKINS-35845] Fix links to not drop query * [JENKINS-35845] use the url config util to get correct path to jenkins * [JENKINS-35845] WIP security commit - refactor i18n class to support listener and subscribe to i18nChanges. Will allow to drop react specific integration via react-i18next. * [JENKINS-35845] WIP security commit * [JENKINS-35845] remove debug statement * [JENKINS-35845] fix import * Task/jenkins 35845 i18n key rename (#579) * [JENKINS-35845] rework i18n keys for home page * [JENKINS-35845] l10n for activity tab * [JENKINS-35845] l10n for branches tab * [JENKINS-35845] l10n for pull requests tab * [JENKINS-35845] l10n for run details -> pipeline * [JENKINS-35845] l10n for run details -> changes, tests, artifacts * [JENKINS-35845] l10n for run details header changes * [JENKINS-35845] pagination; fix typo causing error * [JENKINS-35845] order keys * [JENKINS-35845] WIP security commit to be able to merge master * eslint - formating changes and fix offences * [JENKINS-35845] Remove dep to snapshot-jenkins and implement fallback to default values. Fix tests of all related projects. * [JENKINS-35845] remove duplicate variable * [JENKINS-35845] fix test by adding polyfy again * eslint - formating changes and fix offences * [JENKINS-35845] Fix last test * [JENKINS-35845] fix tests for dashboard * [JENKINS-35845] sync version numbers
- Loading branch information
Showing
61 changed files
with
7,733 additions
and
5,013 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
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 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,80 @@ | ||
import i18next from 'i18next'; | ||
import LngDetector from 'i18next-browser-languagedetector'; | ||
import XHR from 'i18next-xhr-backend'; | ||
|
||
import urlConfig from '../urlconfig'; | ||
|
||
/** | ||
* Init language detector, we are going to use first queryString and then the navigator prefered language | ||
*/ | ||
export const defaultLngDetector = new LngDetector(null, { | ||
// order and from where user language should be detected | ||
order: ['querystring', 'navigator'], | ||
// keys or params to lookup language from | ||
lookupQuerystring: 'language', | ||
}); | ||
const prefix = urlConfig.getJenkinsRootURL() || '/'; | ||
|
||
const loadPath = `${prefix}/i18n/resourceBundle?language={lng}&baseName={ns}`; | ||
/** | ||
* configure the backend for our locale | ||
*/ | ||
export const defaultXhr = new XHR(null, { | ||
loadPath, | ||
allowMultiLoading: false, | ||
parse: (data) => { | ||
// we need to parse the response and then extract the data since the rest is garbage for us | ||
const response = JSON.parse(data); | ||
return response.data; | ||
}, | ||
}); | ||
|
||
/** | ||
* Our default properties for i18next | ||
* @type {{fallbackLng: string, ns: string[], defaultNS: string, preload: string[], keySeparator: boolean, debug: boolean, load: string, interpolation: {prefix: string, suffix: string, escapeValue: boolean}}} | ||
*/ | ||
export const initOptions = { | ||
fallbackLng: 'en', | ||
// have a common namespace used around the full app | ||
ns: ['jenkins.plugins.blueocean.web.Messages', 'jenkins.plugins.blueocean.dashboard.Messages'], | ||
defaultNS: 'jenkins.plugins.blueocean.web.Messages', | ||
preload: ['en'], | ||
keySeparator: false, // we do not have any nested keys in properties files | ||
debug: false, | ||
load: 'all', // --> ['en-US', 'en', 'dev'] | ||
interpolation: { | ||
prefix: '{', | ||
suffix: '}', | ||
escapeValue: false, // not needed for react!! | ||
}, | ||
}; | ||
|
||
/** | ||
* Create a instance of i18next and init it | ||
* in case we are in test mode and run unit test, we deliver a i18next instance that are not using any backend nor language detection | ||
* @param backend {object} - the backend we want to use | ||
* @param lngDetector {object} - the component that detects which language we want to display | ||
* @param options {object} - general options for i18next | ||
* @see defaultOptions | ||
*/ | ||
export const i18n = (backend = defaultXhr, lngDetector = defaultLngDetector, options = initOptions) => { | ||
if (typeof window === 'undefined') { // eslint-disable-line no-undef | ||
return i18next.init({ | ||
lng: 'en', | ||
resources: { | ||
en: { | ||
translation: { | ||
key: 'hello world', | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
return i18next | ||
.use(backend) | ||
.use(lngDetector) | ||
.init(options); | ||
}; | ||
|
||
|
||
export default i18n(defaultXhr, defaultLngDetector, initOptions); |
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
Oops, something went wrong.