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