Skip to content

Commit c317da9

Browse files
authored
Merge pull request #31 from BuildFire/add-more-language
feat/add more language
2 parents 05837f7 + cce99c9 commit c317da9

2 files changed

Lines changed: 117 additions & 58 deletions

File tree

resources/languages.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,38 @@
101101
"maxLength": 20,
102102
"toolTip": "",
103103
"placeholder": "Someone"
104+
},
105+
"day": {
106+
"title": "Day",
107+
"defaultValue": "Day",
108+
"inputType": "text",
109+
"maxLength": 15,
110+
"toolTip": "",
111+
"placeholder": "Day"
112+
},
113+
"hour": {
114+
"title": "Hour",
115+
"defaultValue": "Hour",
116+
"inputType": "text",
117+
"maxLength": 15,
118+
"toolTip": "",
119+
"placeholder": "Hour"
120+
},
121+
"hours": {
122+
"title": "Hours",
123+
"defaultValue": "Hours",
124+
"inputType": "text",
125+
"maxLength": 15,
126+
"toolTip": "",
127+
"placeholder": "Hours"
128+
},
129+
"min": {
130+
"title": "Min",
131+
"defaultValue": "Min",
132+
"inputType": "text",
133+
"maxLength": 15,
134+
"toolTip": "",
135+
"placeholder": "Min"
104136
}
105137
}
106138
},
@@ -334,6 +366,22 @@
334366
"toolTip": "",
335367
"maxLength": 9,
336368
"placeholder": "Cancel"
369+
},
370+
"youGotAnUpVoteTitle": {
371+
"title": "You Got An Upvote Title",
372+
"defaultValue": "You got an upvote",
373+
"inputType": "text",
374+
"toolTip": "",
375+
"maxLength": 100,
376+
"placeholder": "You got an upvote"
377+
},
378+
"youGotAnUpVoteBody": {
379+
"title": "You Got An Upvote Body",
380+
"defaultValue": "${context.plugin.userName} upvoted your suggestion ${context.plugin.itemTitle}",
381+
"inputType": "text",
382+
"toolTip": "",
383+
"maxLength": 100,
384+
"placeholder": "You got an upvote"
337385
}
338386
}
339387
}

widget/controllers/widget.home.controller.js

Lines changed: 69 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -699,96 +699,98 @@ var config = {};
699699
}
700700

701701

702-
const upVoteHandler = (suggestionObj, user, isUserUpvoted)=>{
702+
const upVoteHandler = (suggestionObj, user, isUserUpvoted) => {
703703
checkUserCredits()
704-
.then((res) => {
705-
if (res) {
706-
isUserUpvoted = true;
704+
.then((res) => {
705+
if (res) {
706+
isUserUpvoted = true;
707707
// vote
708-
Analytics.trackAction(
709-
analyticKeys.VOTE_NUMBER.key,
710-
{
711-
votes: 1,
712-
_buildfire: { aggregationValue: 1 },
713-
}
714-
);
715-
716-
suggestionObj.upVoteCount++;
717-
suggestionObj.disableUpvote = true;
718-
suggestionObj.upVotedBy[user._id] = {
719-
votedOn: new Date(),
720-
user: user,
721-
};
722-
723-
if (
724-
suggestionObj.createdBy._id != user._id
725-
) {
726-
buildfire.notifications.pushNotification.schedule(
708+
Analytics.trackAction(
709+
analyticKeys.VOTE_NUMBER.key,
727710
{
728-
title: 'You got an upvote!',
729-
text:
730-
getUserName(user) +
731-
' upvoted your suggestion ' +
732-
suggestionObj.title,
733-
users: [
734-
suggestionObj.createdBy._id,
735-
],
736-
},
737-
function (err) {
738-
if (err) console.error(err);
711+
votes: 1,
712+
_buildfire: { aggregationValue: 1 },
739713
}
740714
);
741-
}
742715

743-
if ($rootScope.settings.selectedPurchaseProductId) {
744-
let credit = Number(
716+
suggestionObj.upVoteCount++;
717+
suggestionObj.disableUpvote = true;
718+
suggestionObj.upVotedBy[user._id] = {
719+
votedOn: new Date(),
720+
user: user,
721+
};
722+
723+
if (suggestionObj.createdBy._id !== user._id) {
724+
votesExpressionOptions.plugin.userName = getUserName(user);
725+
votesExpressionOptions.plugin.itemTitle = suggestionObj.title;
726+
727+
Promise.all([
728+
getLanguageValue('notifications.youGotAnUpVoteTitle'),
729+
getLanguageValue('notifications.youGotAnUpVoteBody')
730+
]).then(([title, text]) => {
731+
buildfire.notifications.pushNotification.schedule(
732+
{
733+
title,
734+
text,
735+
users: [suggestionObj.createdBy._id],
736+
},
737+
function (err) {
738+
if (err) console.error(err);
739+
}
740+
);
741+
}).catch((err) => {
742+
console.error('Error fetching language strings:', err);
743+
});
744+
}
745+
746+
if ($rootScope.settings.selectedPurchaseProductId) {
747+
let credit = Number(
745748
decryptCredit(
746749
res.credits,
747750
secretKey
748751
)
749-
);
750-
credit -= 1;
751-
let payload = {
752-
$set: {
753-
updatedBy: _currentUser.userId,
752+
);
753+
credit -= 1;
754+
let payload = {
755+
$set: {
756+
updatedBy: _currentUser.userId,
754757
credits: encryptCredit(
755758
credit,
756759
secretKey
757760
),
758-
},
759-
};
761+
},
762+
};
760763

761764
votesExpressionOptions.plugin.remainingVotes = credit
762765
return UserCredit.update($scope.currentUserCreditData.id,payload).then(
763766
() => {
764-
buildfire.language.get({stringKey: 'mainScreen.voteConfirmed'}, (err, result) => {
767+
buildfire.language.get({ stringKey: 'mainScreen.voteConfirmed' }, (err, result) => {
765768
if (err) return console.error(err);
766769
buildfire.dialog.toast({
767770
message: result,
768771
type: 'info',
769772
});
770773
});
771-
if(credit === 0){
774+
if (credit === 0) {
772775
Analytics.trackAction(analyticKeys.CONSUMING_CREDITS.key);
773776
}
774777
return res;
775-
}
776-
);
778+
});
779+
} else {
780+
return res;
781+
}
777782
} else {
778-
return res;
783+
return null;
779784
}
780-
} else {
781-
return null;
782-
}
783-
})
784-
.then((res) => {
785+
})
786+
.then((res) => {
785787
if (res)
786788
updateSuggestion(
787789
suggestionObj,
788790
user,
789791
isUserUpvoted
790792
);
791-
});
793+
});
792794
};
793795

794796
const downVoteHandler = (suggestionObj, user, isUserUpvoted)=>{
@@ -1018,11 +1020,20 @@ var config = {};
10181020
const daysDifference = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
10191021

10201022
if(hoursDifference < 24 && hoursDifference != 0){
1021-
return hoursDifference + "hour";
1023+
if (hoursDifference == 1) {
1024+
const hourText = getLanguageString("mainScreen.hour");
1025+
return hoursDifference + hourText;
1026+
}
1027+
else {
1028+
const hoursText = getLanguageString("mainScreen.hours");
1029+
return hoursDifference + hoursText;
1030+
}
10221031
} else if(hoursDifference == 0){
1023-
return minutesDifference + "min"
1032+
const minutesText = getLanguageString("mainScreen.min");
1033+
return minutesDifference + minutesText
10241034
} else if(daysDifference == 1) {
1025-
return "1day"
1035+
const dayText = getLanguageString("mainScreen.day");
1036+
return daysDifference + dayText;
10261037
} else {
10271038
return null;
10281039
}

0 commit comments

Comments
 (0)