Skip to content

Commit

Permalink
gdcc#8 adding link to dataset on success and handling parameters in l…
Browse files Browse the repository at this point in the history
…anguage keys
  • Loading branch information
luddaniel committed Sep 6, 2023
1 parent ac9bba5 commit b7c2b39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/js/fileupload2.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ function initTranslation() {
function initSpanTxt(htmlId, key) {
$('#'+htmlId).text(getLocalizedString(dvLocale, key));
}
function addMessage(type, key) {
$('#messages').html('').append($('<div/>').addClass(type).text(getLocalizedString(dvLocale, key)));
function addMessage(type, key, ...keyArgs) {
$('#messages').html('').append($('<div/>').addClass(type).html(getLocalizedString(dvLocale, key, keyArgs)));
}
async function populatePageMetadata(data) {
var mdFields = data.metadataBlocks.citation.fields;
Expand Down Expand Up @@ -853,8 +853,9 @@ async function directUploadFinished() {
data: fd,
processData: false,
success: function(body, statusText, jqXHR) {
console.log("All files sent to " + siteUrl + '/dataset.xhtml?persistentId=doi:' + datasetPid + '&version=DRAFT');
addMessage('success', 'msgUploadComplete');
var datasetUrl = siteUrl + '/dataset.xhtml?persistentId=' + datasetPid + '&version=DRAFT';
console.log("All files sent to " + datasetUrl);
addMessage('success', 'msgUploadComplete', datasetUrl);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Failure: ' + jqXHR.status);
Expand Down
14 changes: 10 additions & 4 deletions src/js/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const translations = {
msgStartUpload: "Checked files will be uploaded.",
msgNoFile: "No files to upload. Check some files, or refresh to start over.",
msgUploadCompleteRegistering: "Uploads to S3 complete. Now registering all files with the dataset. This may take some time for large numbers of files.",
msgUploadComplete: "Upload complete, all files in dataset. Close this window and refresh your dataset page to see the uploaded files.",
msgUploadComplete: "Upload complete, all files in dataset. Close this window and refresh your dataset page to see the uploaded files : <a href=\"{0}\">{0}</a>",
},
fr: {
title: "Envoi d'un dossier",
Expand All @@ -30,17 +30,23 @@ const translations = {
msgStartUpload: "Les fichiers cochés seront envoyés.",
msgNoFile: "Aucun fichier à envoyer. Cochez certains fichiers ou rafraîchissez la page pour recommencer.",
msgUploadCompleteRegistering: "Envois vers S3 terminés. Enregistrement de tous les fichiers en cours dans le jeu de données. Cela peut prendre du temps pour un grand nombre de fichiers.",
msgUploadComplete: "Envoi terminé, tous les fichiers sont dans le jeu de données. Fermez cette fenêtre et rafraîchissez la page de votre jeu de données pour voir les fichiers envoyés.",
msgUploadComplete: "Envoi terminé, tous les fichiers sont dans le jeu de données. Fermez cette fenêtre et rafraîchissez la page de votre jeu de données pour voir les fichiers envoyés : <a href=\"{0}\">{0}</a>",
},
};

export default function getLocalizedString(locale, key) {
export default function getLocalizedString(locale, key, keyArgs) {
if(!locale || !translations[locale]) {
locale = defaultLocale;
console.log('getLocalizedString - locale empty or unknown, using defaultLocale: '+defaultLocale)
}
if (translations[locale] && translations[locale][key]) {
return translations[locale][key];
var tr = translations[locale][key];
if(keyArgs && Array.isArray(keyArgs)) {
for (var i = 0; i < keyArgs.length; i++) {
tr = tr.replaceAll('{'+i+'}',keyArgs[i]);
}
}
return tr;
}
console.log('getLocalizedString - transalation not found with locale: '+locale+' and key:'+key);
return key;
Expand Down

0 comments on commit b7c2b39

Please sign in to comment.