@@ -30,7 +30,9 @@ use phpweb\UserNotes\UserNote;
30
30
*
31
31
* @param array<string, UserNote> $notes
32
32
*/
33
- function manual_notes ($ notes , $ repo = 'en ' ):void {
33
+ function manual_notes ($ notes ):void {
34
+ global $ LANG ;
35
+
34
36
// Get needed values
35
37
list ($ filename ) = $ GLOBALS ['PGI ' ]['this ' ];
36
38
@@ -42,14 +44,15 @@ function manual_notes($notes, $repo = 'en'):void {
42
44
$ sorter = new Sorter ();
43
45
$ sorter ->sort ($ notes );
44
46
47
+ $ addNote = autogen ('add_a_note ' , $ LANG );
45
48
// Link target to add a note to the current manual page,
46
49
// and it's extended form with a [+] image
47
50
$ addnotelink = '/manual/add-note.php?sect= ' . $ filename .
48
51
'&repo= ' . $ repo .
49
52
'&redirect= ' . $ _SERVER ['BASE_HREF ' ];
50
53
$ addnotesnippet = make_link (
51
54
$ addnotelink ,
52
- "+<small>add a note </small> " ,
55
+ "+<small> $ addNote </small> " ,
53
56
);
54
57
55
58
$ num_notes = count ($ notes );
@@ -58,17 +61,19 @@ function manual_notes($notes, $repo = 'en'):void {
58
61
$ noteCountHtml = "<span class= \"count \"> $ num_notes note " . ($ num_notes == 1 ? '' : 's ' ) . "</span> " ;
59
62
}
60
63
64
+ $ userContributedNotes = autogen ('user_contributed_notes ' , $ LANG );
61
65
echo <<<END_USERNOTE_HEADER
62
66
<section id="usernotes">
63
67
<div class="head">
64
68
<span class="action"> {$ addnotesnippet }</span>
65
- <h3 class="title">User Contributed Notes {$ noteCountHtml }</h3>
69
+ <h3 class="title"> $ userContributedNotes {$ noteCountHtml }</h3>
66
70
</div>
67
71
END_USERNOTE_HEADER ;
68
72
69
73
// If we have no notes, then inform the user
70
74
if ($ num_notes === 0 ) {
71
- echo "\n <div class= \"note \">There are no user contributed notes for this page.</div> " ;
75
+ $ noUserContributedNotes = autogen ('no_user_notes ' , $ LANG );
76
+ echo "\n <div class= \"note \"> $ noUserContributedNotes</div> " ;
72
77
} else {
73
78
// If we have notes, print them out
74
79
echo '<div id="allnotes"> ' ;
@@ -334,7 +339,7 @@ PAGE_TOOLS;
334
339
}
335
340
336
341
function manual_language_chooser ($ currentlang , $ currentpage ) {
337
- global $ ACTIVE_ONLINE_LANGUAGES ;
342
+ global $ ACTIVE_ONLINE_LANGUAGES , $ LANG ;
338
343
339
344
// Prepare the form with all the options
340
345
$ othersel = ' selected="selected" ' ;
@@ -350,10 +355,11 @@ function manual_language_chooser($currentlang, $currentpage) {
350
355
$ out [] = "<option value='help-translate.php' {$ othersel }>Other</option> " ;
351
356
$ format_options = implode ("\n" . str_repeat (' ' , 6 ), $ out );
352
357
358
+ $ changeLanguage = autogen ('change_language ' , $ LANG );
353
359
$ r = <<<CHANGE_LANG
354
360
<form action="/manual/change.php" method="get" id="changelang" name="changelang">
355
361
<fieldset>
356
- <label for="changelang-langs">Change language :</label>
362
+ <label for="changelang-langs"> $ changeLanguage :</label>
357
363
<select onchange="document.changelang.submit()" name="page" id="changelang-langs">
358
364
{$ format_options }
359
365
</select>
@@ -364,7 +370,7 @@ CHANGE_LANG;
364
370
}
365
371
366
372
function manual_footer ($ setup ): void {
367
- global $ USERNOTES , $ __RELATED ;
373
+ global $ USERNOTES , $ __RELATED, $ LANG ;
368
374
369
375
$ id = substr ($ setup ['this ' ][0 ], 0 , -4 );
370
376
$ repo = strtolower ($ setup ["head " ][1 ]); // pt_BR etc.
@@ -393,18 +399,23 @@ function manual_footer($setup): void {
393
399
$ contributors = '<a href="?contributors">All contributors.</a> ' ;
394
400
}
395
401
402
+ $ improveThisPage = autogen ('improve_this_page ' , $ LANG );
403
+ $ howToImproveThisPage = autogen ('how_to_improve_this_page ' , $ LANG );
404
+ $ contributionGuidlinesOnGithub = autogen ('contribution_guidlines_on_github ' , $ LANG );
405
+ $ submitPullRequest = autogen ('submit_a_pull_request ' , $ LANG );
406
+ $ reportBug = autogen ('report_a_bug ' , $ LANG );
396
407
echo <<<CONTRIBUTE
397
408
<div class="contribute">
398
- <h3 class="title">Improve This Page </h3>
409
+ <h3 class="title"> $ improveThisPage </h3>
399
410
<div>
400
411
$ lastUpdate $ contributors
401
412
</div>
402
413
<div class="edit-bug">
403
- <a href="https://github.com/php/doc-base/blob/master/README.md" title="This will take you to our contribution guidelines on GitHub. " target="_blank" rel="noopener noreferrer">Learn How To Improve This Page </a>
414
+ <a href="https://github.com/php/doc-base/blob/master/README.md" title=" $ contributionGuidlinesOnGithub " target="_blank" rel="noopener noreferrer"> $ howToImproveThisPage </a>
404
415
•
405
- <a href=" {$ edit_url }">Submit a Pull Request </a>
416
+ <a href=" {$ edit_url }"> $ submitPullRequest </a>
406
417
•
407
- <a href="https://github.com/php/doc- {$ repo }/issues/new?body=From%20manual%20page:%20https:%2F%2Fphp.net%2F $ id%0A%0A---">Report a Bug </a>
418
+ <a href="https://github.com/php/doc- {$ repo }/issues/new?body=From%20manual%20page:%20https:%2F%2Fphp.net%2F $ id%0A%0A---"> $ reportBug </a>
408
419
</div>
409
420
</div>
410
421
CONTRIBUTE ;
@@ -459,3 +470,35 @@ CONTRIBUTORS;
459
470
manual_footer ($ setup );
460
471
exit ;
461
472
}
473
+
474
+ function autogen (string $ text , string $ lang ) {
475
+ static $ translations = [];
476
+
477
+ $ lang = ($ lang === "" ) ? "en " : $ lang ;
478
+ if (isset ($ translations [$ lang ])) {
479
+ if (isset ($ translations [$ lang ][$ text ]) && $ translations [$ lang ][$ text ] !== "" ) {
480
+ return $ translations [$ lang ][$ text ];
481
+ }
482
+ if ($ lang !== "en " ) {
483
+ // fall back to English if text is not defined for the given language
484
+ return autogen ($ text , "en " );
485
+ }
486
+ // we didn't find the English text either
487
+ throw new \InvalidArgumentException ("Cannot autogenerate text for ' $ text' " );
488
+ }
489
+
490
+ $ translationFile = __DIR__ . \DIRECTORY_SEPARATOR . "ui_translation " . \DIRECTORY_SEPARATOR . $ lang . ".ini " ;
491
+
492
+ if (!\file_exists ($ translationFile )) {
493
+ if ($ lang !== "en " ) {
494
+ // fall back to English if translation file is not found
495
+ return autogen ($ text , "en " );
496
+ }
497
+ // we didn't find the English file either
498
+ throw new \Exception ("Cannot find translation files " );
499
+ }
500
+
501
+ $ translations [$ lang ] = \parse_ini_file ($ translationFile );
502
+
503
+ return autogen ($ text , $ lang );
504
+ }
0 commit comments