Skip to content

Commit 2312f03

Browse files
authored
Merge pull request #64 from UMB-CS-682-Team-03/fix_translation_all_words
Fix translation all words
2 parents 07b5fd0 + f7e28ad commit 2312f03

File tree

3 files changed

+160
-107
lines changed

3 files changed

+160
-107
lines changed

README.md

Lines changed: 78 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,3 @@
1-
# Development Setup
2-
3-
### Clone mercurial repository.
4-
```shell
5-
hg clone http://hg.code.sf.net/p/roundup/code roundup
6-
```
7-
8-
### Make python virtual env and activate it
9-
```shell
10-
cd roundup
11-
python -m venv .
12-
```
13-
#### For linux and mac
14-
```shell
15-
source bin/activate
16-
```
17-
#### For windows powershell
18-
```shell
19-
.\scripts\Activate.ps1
20-
```
21-
22-
### Install roundup
23-
```shell
24-
python -m pip install .
25-
```
26-
27-
### Clone tracker only repo.
28-
```shell
29-
git clone https://github.com/UMB-CS-682-Team-03/tracker.git
30-
```
31-
32-
### Init the demo tracker with default ./demo
33-
```shell
34-
roundup-demo -b sqlite
35-
```
36-
37-
### Move the files from tracker dir to demo dir
38-
#### For linux and mac
39-
```shell
40-
cp -r ./tracker/**/* ./demo
41-
cp -r ./tracker/.git ./tracker/.gitignore ./demo
42-
```
43-
#### For windows powershell
44-
```shell
45-
xcopy .\tracker .\demo /s #say yes to all
46-
```
47-
48-
1. Now you are done setting up developing environment.
49-
2. Open the roundup folder in VScode.
50-
3. Any new changes are only to be done in demo directory.
51-
4. git is initialized to track origin in demo directory (for windows check if .git folder is copied to the demo)
52-
531
# Roundup - Classhelper
542
## `<roundup-classhelper>`
553
## Why there is need of `<roundup-classhelper>` in the issue tracker?
@@ -224,7 +172,81 @@ Copy the following files into your Roundup instance `html` directory:
224172

225173
After copying these files, you can use the `<roundup-classhelper>` component in your Roundup templates.
226174

175+
# Missing translations
176+
To set up translations for the <roundup-classhelper> component, follow these steps:
177+
178+
1. In your Roundup instance's Demo/locale directory, create a new file if not exists with the name __.po (e.g., de.po for German).
179+
180+
2. After the header, add the translation entries for the <roundup-classhelper> component.
181+
For example next and submit are not being shown for German, you can add:
182+
msgid "submit"
183+
msgstr "gehen"
184+
185+
msgid "next"
186+
msgstr "nächste"
187+
188+
msgid "name"
189+
msgstr "name"
190+
191+
The **msgid** here is case sensitive therefore be careful.
192+
193+
3. Save the __.po file.
194+
195+
4. Restart your Roundup instance.
227196

197+
This should get you the missing translations, for more details refer roundup documentation for translations.
198+
199+
# Development Setup
200+
201+
### Clone mercurial repository.
202+
```shell
203+
hg clone http://hg.code.sf.net/p/roundup/code roundup
204+
```
205+
206+
### Make python virtual env and activate it
207+
```shell
208+
cd roundup
209+
python -m venv .
210+
```
211+
#### For linux and mac
212+
```shell
213+
source bin/activate
214+
```
215+
#### For windows powershell
216+
```shell
217+
.\scripts\Activate.ps1
218+
```
219+
220+
### Install roundup
221+
```shell
222+
python -m pip install .
223+
```
224+
225+
### Clone tracker only repo.
226+
```shell
227+
git clone https://github.com/UMB-CS-682-Team-03/tracker.git
228+
```
229+
230+
### Init the demo tracker with default ./demo
231+
```shell
232+
roundup-demo -b sqlite
233+
```
234+
235+
### Move the files from tracker dir to demo dir
236+
#### For linux and mac
237+
```shell
238+
cp -r ./tracker/**/* ./demo
239+
cp -r ./tracker/.git ./tracker/.gitignore ./demo
240+
```
241+
#### For windows powershell
242+
```shell
243+
xcopy .\tracker .\demo /s #say yes to all
244+
```
245+
246+
1. Now you are done setting up developing environment.
247+
2. Open the roundup folder in VScode.
248+
3. Any new changes are only to be done in demo directory.
249+
4. git is initialized to track origin in demo directory (for windows check if .git folder is copied to the demo)
228250

229251
# Running the Test Suite
230252

@@ -233,13 +255,12 @@ After copying these files, you can use the `<roundup-classhelper>` component in
233255
- GeckoDriver (for Firefox)
234256

235257
### Installation Instructions
236-
1. **Selenium Installation**:
237-
Open your terminal or command prompt and run:
238-
python -m pip install selenium==4.18.1
239258

240-
2. **GeckoDriver Installation**:
241-
pip install geckodriver==0.0.1
259+
Enable the python virtual environment then proceed to install the following packages
242260

261+
```shell
262+
python -m pip install selenium geckodriver
263+
```
243264

244265
#### To run the code in a Headless Environment:
245266
Set "HEADLESS = TRUE " in line 12.
@@ -250,4 +271,3 @@ After copying these files, you can use the `<roundup-classhelper>` component in
250271

251272
### Run the test suite
252273
python test_classhelper.py
253-

html/classhelper.js

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const CLASSHELPER_POPUP_URL = "about:blank";
3131
const CLASSHELPER_POPUP_TARGET = "_blank";
3232

3333
const CLASSHELPER_TABLE_SELECTION_NONE = "table-selection-none";
34+
const CLASSHELPER_TRANSLATION_KEYWORDS = ["apply", "cancel", "next", "prev", "search", "reset"];
3435

3536
const ALTERNATIVE_DROPDOWN_PATHNAMES = {
3637
"roles": "/rest/roles"
@@ -149,12 +150,6 @@ class ClassHelper extends HTMLElement {
149150

150151
const initialRequestURL = ClassHelper.getRestURL(this.trackerBaseURL, this.helpurlProps);
151152

152-
ClassHelper.fetchTranslations()
153-
.catch(error => {
154-
console.warn("Classhelper failed in translating.")
155-
console.error(error);
156-
});
157-
158153
this.fetchDropdownsData()
159154
.catch(error => {
160155
// Top level handling for dropdowns errors.
@@ -280,20 +275,39 @@ class ClassHelper extends HTMLElement {
280275
return;
281276
}
282277

283-
let translations = {
284-
"Apply": "Apply",
285-
"Cancel": "Cancel",
286-
"Next": "Next",
287-
"Prev": "Prev",
288-
"Search": "Search",
289-
"Reset": "Reset"
290-
};
291-
ClassHelper.translations = translations;
278+
const keys = new Set();
279+
280+
const classhelpers = document.getElementsByTagName(CLASSHELPER_TAG_NAME);
281+
for (let classhelper of classhelpers) {
282+
if (classhelper.dataset.searchWith) {
283+
classhelper.dataset.searchWith
284+
.split(',')
285+
.forEach(param => {
286+
keys.add(param.split("[]")[0]);
287+
});
288+
}
289+
290+
const a = classhelper.querySelector("a");
291+
if (a && a.dataset.helpurl) {
292+
let searchParams = new URLSearchParams(a.dataset.helpurl.split("?")[1]);
293+
let properties = searchParams.get("properties");
294+
if (properties) {
295+
properties.split(',').forEach(key => keys.add(key));
296+
}
297+
}
298+
}
299+
300+
CLASSHELPER_TRANSLATION_KEYWORDS.forEach(key => keys.add(key));
301+
302+
ClassHelper.translations = {};
303+
for (let key of keys) {
304+
ClassHelper.translations[key] = key;
305+
}
292306

293307
let tracker = window.location.pathname.split('/')[1];
294308
let url = new URL(window.location.origin + "/" + tracker);
295309
url.searchParams.append("@template", "translation");
296-
url.searchParams.append("properties", Object.keys(translations).join(','));
310+
url.searchParams.append("properties", Array.from(keys.values()).join(','));
297311

298312
let resp, json;
299313

@@ -321,7 +335,9 @@ class ClassHelper extends HTMLElement {
321335
throw new Error(message);
322336
}
323337

324-
ClassHelper.translations = json;
338+
for (let entry of Object.entries(json)) {
339+
ClassHelper.translations[entry[0]] = entry[1];
340+
}
325341
}
326342

327343
async fetchDropdownsData() {
@@ -547,7 +563,7 @@ class ClassHelper extends HTMLElement {
547563
const label = document.createElement("label");
548564
label.classList.add("search-label"); // Add class for styling
549565
label.setAttribute("for", param);
550-
label.textContent = param + ":";
566+
label.textContent = ClassHelper.translations[param] + ":";
551567

552568
let input;
553569
if (this.dropdownsData[param]) {
@@ -602,7 +618,7 @@ class ClassHelper extends HTMLElement {
602618
buttonCell.colSpan = 1;
603619

604620
const search = document.createElement("button");
605-
search.textContent = ClassHelper.translations["Search"];
621+
search.textContent = ClassHelper.translations["search"];
606622
search.classList.add("search-button"); // Add class for styling
607623
search.addEventListener("click", (e) => {
608624
e.preventDefault();
@@ -615,7 +631,7 @@ class ClassHelper extends HTMLElement {
615631
});
616632

617633
const reset = document.createElement("button");
618-
reset.textContent = ClassHelper.translations["Reset"];
634+
reset.textContent = ClassHelper.translations["reset"];
619635
reset.classList.add("reset-button"); // Add class for styling
620636
reset.addEventListener("click", (e) => {
621637
e.preventDefault();
@@ -665,7 +681,7 @@ class ClassHelper extends HTMLElement {
665681

666682
const prev = document.createElement("button");
667683
prev.innerHTML = "<";
668-
prev.setAttribute("aria-label", ClassHelper.translations["Prev"]);
684+
prev.setAttribute("aria-label", ClassHelper.translations["prev"]);
669685
prev.setAttribute("disabled", "disabled");
670686
if (prevUrl) {
671687
prev.removeAttribute("disabled");
@@ -680,7 +696,7 @@ class ClassHelper extends HTMLElement {
680696

681697
const next = document.createElement("button");
682698
next.innerHTML = ">";
683-
next.setAttribute("aria-label", ClassHelper.translations["Next"]);
699+
next.setAttribute("aria-label", ClassHelper.translations["next"]);
684700
next.setAttribute("disabled", "disabled");
685701
if (nextUrl) {
686702
next.removeAttribute("disabled");
@@ -714,7 +730,7 @@ class ClassHelper extends HTMLElement {
714730
}
715731

716732
const cancel = document.createElement("button");
717-
cancel.textContent = ClassHelper.translations["Cancel"];
733+
cancel.textContent = ClassHelper.translations["cancel"];
718734
cancel.addEventListener("click", () => {
719735
this.dispatchEvent(new CustomEvent("valueSelected", {
720736
detail: {
@@ -726,7 +742,7 @@ class ClassHelper extends HTMLElement {
726742
const apply = document.createElement("button");
727743
apply.id = "popup-apply";
728744
apply.classList.add("popup-apply");
729-
apply.textContent = ClassHelper.translations["Apply"];
745+
apply.textContent = ClassHelper.translations["apply"];
730746
apply.addEventListener("click", () => {
731747
this.dispatchEvent(new CustomEvent("valueSelected", {
732748
detail: {
@@ -774,7 +790,7 @@ class ClassHelper extends HTMLElement {
774790

775791
headers.forEach(header => {
776792
const th = document.createElement('th');
777-
th.textContent = header;
793+
th.textContent = ClassHelper.translations[header];
778794
headerRow.appendChild(th);
779795
});
780796
thead.appendChild(headerRow);
@@ -830,19 +846,7 @@ class ClassHelper extends HTMLElement {
830846
}
831847

832848
// Create table footer with the same column values as headers
833-
const footerRow = document.createElement('tr');
834-
835-
if (includeCheckbox) {
836-
let footThx = document.createElement("th");
837-
footThx.textContent = "X";
838-
footerRow.appendChild(footThx);
839-
}
840-
841-
headers.forEach(header => {
842-
const th = document.createElement('th');
843-
th.textContent = header;
844-
footerRow.appendChild(th);
845-
});
849+
const footerRow = headerRow.cloneNode(true);
846850
tfoot.appendChild(footerRow);
847851

848852
// Assemble the table
@@ -1268,7 +1272,7 @@ function enableClassHelper() {
12681272
return;
12691273
}
12701274

1271-
/**@todo - make api call? get 404 then early return? */
1275+
/** make api call if error then do not register*/
12721276
// http://localhost/demo/rest
12731277

12741278
fetch("rest")
@@ -1279,6 +1283,11 @@ function enableClassHelper() {
12791283
return;
12801284
}
12811285
customElements.define(CLASSHELPER_TAG_NAME, ClassHelper);
1286+
ClassHelper.fetchTranslations()
1287+
.catch(error => {
1288+
console.warn("Classhelper failed in translating.")
1289+
console.error(error);
1290+
});
12821291
}).catch(err => {
12831292
console.error(err);
12841293
});

0 commit comments

Comments
 (0)