Commit graph

109 commits

Author SHA1 Message Date
Amir Sarabadani
308e6427ae Revert "Make LocalisationCache a service"
This reverts commits:
 - 76a940350d
 - b78b8804d0
 - 2e52f48c2e
 - e4468a1d6b

Bug: T231200
Bug: T231198
Change-Id: I1a7e46a979ae5c9c8130dd3927f6663a216ba753
2019-08-26 18:28:26 +02:00
Aryeh Gregor
2e52f48c2e Split some Language methods to LanguageNameUtils
These are static methods that have to do with processing language names
and codes. I didn't include fallback behavior, because that would mean a
circular dependency with LocalisationCache.

In the new class, I renamed AS_AUTONYMS to AUTONYMS, and added a class
constant DEFINED for 'mw' to match the existing SUPPORTED and ALL. I
also renamed fetchLanguageName(s) to getLanguageName(s).

There is 100% test coverage for the code in the new class.

Change-Id: I245ae94bfc1f62b6af75ea57525139adf2539fe6
2019-08-23 12:52:35 +03:00
Aryeh Gregor
e4468a1d6b Make LocalisationCache a service
This removes Language::$dataCache without deprecation, because 1) I
don't know of a way to properly simulate it in the new paradigm, and 2)
I found no direct access to the member outside of the Language and
LanguageTest classes.

Change-Id: Iaa86c48e7434f081a53f5bae8723c37c5a34f503
2019-08-22 14:25:18 +03:00
Jack Phoenix
b704c9f4de Add 'avoidhours' option to Language#formatTimePeriod
Example use case: in some skins we want to show how many *days* ago a page was edited, but we don't really care about the precise _hours_.
Thus we'll set [ 'avoid' => 'avoidhours' ] when calling Language#formatTimePeriod to output something like "Page last edited 60 days ago" instead of "Page last edited 60 days 9 hours ago".

Change-Id: I0a737aab14ccb2b8d4eccdc41e1eb9232eedcb8a
2019-05-10 11:06:00 +03:00
rxy
b7d53539f0 Add support for new Japanese era name "Reiwa"
Bug: T219728
Change-Id: I28c26291c38e7e6c167011472236fb81a8adf032
2019-04-20 11:24:26 +00:00
Giuseppe Lavagetto
d46835ef4f Add ability to override mb_strtoupper in Language::ucfirst
Different PHP versions treat unicode differently, and specifically some
wiki resources become unreachable if mb_strtoupper's behavior has changed.
This patch allows to introduce an override table that allows to smooth
the transition period.

It also provides maintenance scripts to generate such an override table.

Bug: T219279
Change-Id: I0503ff4207fded4648c58c7b50e67c55422a4849
2019-04-17 15:18:44 +00:00
C. Scott Ananian
fcbde8ae4e Make Language::hasVariant() more strict
In d59f27aeab we made
LanguageConverter::validateVariant() try harder to convert a variant
into an acceptable MediaWiki-internal form, looking at deprecated
codes and BCP 47 aliases.  However, this misled Language::hasVariant()
into thinking that bogus names (like all-uppercase strings) were
acceptable variant names, which then led exceptions when they were
passed to the various conversion methods.

This is a belt-and-suspenders patch for T207433 -- in that case we
shouldn't have created a Language object with code 'sr-cyrl' in the
first place, but once one was created we shouldn't have tried to
ask LanguageSr to convert texts to 'sr-cyrl'.  The latter problem
is fixed by this patch.

Bug: T207433
Change-Id: Id993bc7989144b5031a551662e8e492bd23f698a
2018-10-22 16:35:26 -04:00
Fomafix
50944a1410 Deprecate Language::setCode as public method
setCode changes the language code for the Language object but it also
replaces the whole language codes for all Language objects.

> $lang = Language::factory( 'fr' )

> $lang2 = Language::factory( 'fr' )

> $lang->setCode( 'it' )

> print $lang2->getCode()
it
> $lang3 = Language::factory( 'fr' )

> print $lang3->getCode()
it

Better assign a new Language object.

Also add more tests for Language::equals.

Depends-On: I61439bac82021344c3f9a6056cccd937b3450af2
Depends-On: I2d9e551d6eb33f28f42aeaf48160eba21b83881f
Change-Id: I201b479f58e63c9c40fb8a3ec9575a551fb35235
2018-10-02 23:48:53 -07:00
Aryeh Gregor
63d7f2ad13 Automatically reset namespace caches when needed
This avoids error-prone code written separately in every test.  In
addition to no existing tests resetting the TitleFormatter (more
services probably need to be reset as well), they mostly reset only the
namespace cache on $wgContLang, which wouldn't help for any other
language.

The parser test runner still doesn't do this, but maybe it should.

Change-Id: I44b7a1aec48f14b0950907fa14bd0df80f674296
2018-08-01 16:30:08 +03:00
jenkins-bot
8c96aec32c Merge "Fix the bug for dates between 1912 and 1941 in Thai language" 2018-07-10 08:55:56 +00:00
Bartosz Dziewoński
0313128b10 Use PHP 7 "\u{NNNN}" Unicode codepoint escapes in string literals
In cases where we're operating on text data (and not binary data),
use e.g. "\u{00A0}" to refer directly to the Unicode character
'NO-BREAK SPACE' instead of "\xc2\xa0" to specify the bytes C2h A0h
(which correspond to the UTF-8 encoding of that character). This
makes it easier to look up those mysterious sequences, as not all
are as recognizable as the no-break space.

This is not enforced by PHP, but I think we should write those in
uppercase and zero-padded to at least four characters, like the
Unicode standard does.

Note that not all "\xNN" escapes can be automatically replaced:
* We can't use Unicode escapes for binary data that is not UTF-8
  (e.g. in code converting from legacy encodings or testing the
  handling of invalid UTF-8 byte sequences).
* '\xNN' escapes in regular expressions in single-quoted strings
  are actually handled by PCRE and have to be dealt with carefully
  (those regexps should probably be changed to use the /u modifier).
* "\xNN" referring to ASCII characters ("\x7F" and lower) should
  probably be left as-is.

The replacements in this commit were done semi-manually by piping
the existing "\xNN" escapes through the following terrible Ruby
script I devised:

  chars = eval('"' + ARGV[0] + '"').force_encoding('utf-8')
  puts chars.split('').map{|char|
    '\\u{' + char.ord.to_s(16).upcase.rjust(4, '0') + '}'
  }.join('')

Change-Id: Idc3dee3a7fb5ebfaef395754d8859b18f1f8769a
2018-06-04 16:20:13 +00:00
Bartosz Dziewoński
4fd27f006f Use PHP 5.6 '**' operator instead of 'pow()' function
Change-Id: Ieb22e1dbfcffaa4e7b3dcfabbcc999e5dd59a4bf
2018-05-30 18:05:19 -07:00
superyetkin
3aaa2367b2 Fix the bug for dates between 1912 and 1941 in Thai language
Added an if-else block to see if the parameters passed to the function
designate a year between 1912 and 1941 or not. Resulting month values
are also adjusted.
Added a unit test for the related formatting.

Bug: T68648
Change-Id: Ic676b5c140de8878971a786a1a1811770a848016
2018-05-12 15:10:13 +00:00
petarpetkovic
2d2575852c Truncate tag filter descriptions
Introduce truncateInternal() method in Language class, based on
existing truncate() method. New method abstracts string truncation,
allowing users to specify callable functions for text length measurement
and string truncation.

New method, truncateInternal(), is used to provide two options for
text truncation:
* For DB usage: truncateForDatabase() method is truncating text by
number of bytes.
* For UI usage: truncateForVisual() method is truncating text by number
of characters, using multibyte string PHP methods.

Old truncate() method is deprecated and just returns the results of
truncateForDatabase() method.

Newly introduced truncateForVisual() method is used for
truncation of long tag descriptions in RCFilters menu.

Bug: T179626
Change-Id: Ib01a8c303304064dde3ce983b817d93a88a5affd
2018-02-09 22:45:20 +01:00
Umherirrender
255d76f2a1 build: Updating mediawiki/mediawiki-codesniffer to 15.0.0
Clean up use of @codingStandardsIgnore
- @codingStandardsIgnoreFile -> phpcs:ignoreFile
- @codingStandardsIgnoreLine -> phpcs:ignore
- @codingStandardsIgnoreStart -> phpcs:disable
- @codingStandardsIgnoreEnd -> phpcs:enable

For phpcs:disable always the necessary sniffs are provided.
Some start/end pairs are changed to line ignore

Change-Id: I92ef235849bcc349c69e53504e664a155dd162c8
2018-01-01 14:10:16 +01:00
Kunal Mehta
fc23633035 Add @covers tags to languages tests
I removed comments that merely repeated the location of the class being
tested. There are other tests in this directory that don't have a
corresponding class and need further investigation.

Change-Id: Ic16f0887b5030ac53fab4382cfaedfb5426cdb08
2017-12-28 08:52:56 +00:00
Sam Wilson
313675320f Always return a string from Language::formatNum()
It says it returns a string, and so it should.

Bug: T182277
Change-Id: Ic68c65c634c2557a1d07281623cd6c971b000323
2017-12-07 13:59:56 +08:00
zoranzoki21
f0828ff475 Removed Toki Pona localization files
Bug: T132899
Bug: T178730
Change-Id: I4c61b3ef42cdc24fee74587965240ca08242867e
2017-10-24 21:27:47 +00:00
Liangent
d8375bee24 New language variant 'en-x-piglatin' for easier variant testing
Guarded by the $wgUsePigLatinVariant variable, off by default.

Pig Latin is a language game where words in English are altered
according to the following rules:

* Words starting with a vowel have a '-way' suffix appended.
* Words starting with a consonant have the initial consonants (or 'qu'
  group) moved to the end and an '-ay' suffix appended.

https://en.wikipedia.org/wiki/Pig_Latin

* Added 'en-x-piglatin' as a language name.
* Added 'en' to LanguageConverter::$languagesWithVariants.
* Added LanguageEn class and its corresponding EnConverter which
  provides one-way translation from English to Pig Latin.
* Some minor internal changes in code that assumed that English
  doesn't have a language class or converter.

Bug: T45547
Depends-On: I1d9691c784032669979f8109c9a5f65cbf4122c9
Change-Id: I7fa2d85d6364958c5138366e8b4504a2697a8731
2017-06-12 16:59:57 -04:00
James D. Forrester
1e9c361960 tests: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I46261416f7603558dceb76ebe695a5cac274e417
2017-02-21 02:14:34 +00:00
Zhuyifei1999
0effd172ce translateBlockExpiry: Duration is block expiry minus current time
For relative timestamps in $str, strtotime( $str, $now ) returns an
absolute Unix timestamp $str since $now, and this timestamp is given
to $time. However, Language::formatDuration expects a time duration,
not an absolute timestamp. We obtain this duration from the difference
between $time, the absolute timestamp of block expiry, and $now, the
absolute timestamp of the time in which the block action happened.

Tests have been added to test both this patch and 01936fa, the patch
that caused this regression.

Bug: T156453
Change-Id: I6fd8c02dc3c6456067fe25cb9f33f5b4c78332aa
2017-01-28 07:22:00 +00:00
Marius Hoch
9ca0f6c620 Only attempt to calculate the TTL in Language::sprintfDate if needed
Change-Id: Ifd24c9206be05bb4fd2277efc574c9d1018e1957
2016-06-23 12:36:25 +02:00
daniel
bbd518baff add LanguageTest::testEquals for Id7ed6a21c
Change-Id: I99ea4c51bfc5245eab0bcca73870c56a6fab2c43
2016-05-23 16:45:06 +02:00
Reedy
83fb19cb13 Swap the rest of array() -> []
Change-Id: I76a7259ed952a0673a1941f08b39b545211fba07
2016-03-30 22:04:58 +00:00
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Roan Kattouw
e4d6238c00 Language::truncate(): don't chop up multibyte characters when input contains newlines
To detect whether the truncation had chopped up a multibyte
character after the first byte, a regex was used. But in this
regex, the dot (.) didn't match newlines, so it failed to
detect chopped multibyte characters (after the first byte)
if there was a newline preceding the chopped character.

Bug: T116693
Change-Id: I66e4fd451acac0a1019da7060d5a37d70963a15a
2015-10-26 20:17:37 -07:00
This, that and the other
31d0283957 Improve wording of "size-bytes" and "size-pixel" messages
"B" and "P" are vanishingly rare abbreviations for "bytes" and "pixels"
respectively. Let's use the full English terms for these, combined with
a PLURAL magic word for good measure.

Change-Id: Id59c4b9dea2c13940ae790b6a236ac08abe0a768
2015-08-30 15:23:13 +10:00
David Chan
f5c88ef8e5 Add {{bidi:}} syntax for directionality-safe arguments
In parallel with jquery.i18n version:
https://github.com/wikimedia/jquery.i18n/pull/76

Bug: T104472
Change-Id: I25afa50ab1e0521bd0b3779cbd16b6c190d72722
2015-07-01 11:06:45 -07:00
Amir E. Aharoni
c9678525eb Rewrite Language::hebrewNumeral()
Use arrays instead of strings, to avoid using
string functions with Unicode.

Handle thousands according to how years like 1000, 2000, etc.
are named in the Hebrew Wikipedia.

Bug: T97444
Change-Id: I5334e86793d28dfcf8939a249b03a5ea85fa4e69
2015-06-02 15:10:52 +02:00
Amir E. Aharoni
399d00e7e7 Add tests for Language::hebrewNumeral()
Some failing tests are commented out and will be properly fixed
in subsequent commits.

Bug: T97444
Change-Id: I19721b5dc3dc6bbe923d9bf401fcf5d765fb7a7c
2015-06-02 12:26:48 +00:00
umherirrender
cd80906d4a Change @return to start with type
MediaWiki default is "@return type Description", so set a type after
return and start the description with a capital letter. Also use the
more common spelling of boolean.

See http://phpdoc.org/docs/latest/references/phpdoc/tags/return.html for
more about @return

Change-Id: I4e5198822fe92836f9cef9918a9fc1a1a1e0a043
2014-08-20 20:35:41 +02:00
Chad Horohoe
fca0d37a2c Language::isValidBuiltInCode() should not accept uppercase input
The results of this function are used to decide whether a code is
valid for loading an i18n file without any further normalization.

Partially reverts 93348f3 which made the regular expression case-
insensitive. Per IRC discussion, language codes should always be
lowercase and it's up to callers to deal with that.

Change-Id: I8975c3374a37935080d9f7eca6a602e32f67a87b
2014-07-16 18:20:22 +00:00
Jackmcbarn
d998c8e96c Return a TTL when formatting times
Add an out parameter to Language::sprintfDate that returns the amount of
time that its output is valid for (e.g., an output format of 'Y-m-d' at
11:50 PM would be valid for 600 seconds).

Change-Id: I3f5a80aa4d303f92c97d24ab780af920894d24ef
2014-06-01 14:10:28 -04:00
jenkins-bot
ab2d63b53e Merge "Fix Language::parseFormattedNumber for lzh and zh-classical" 2014-04-25 07:13:29 +00:00
aude
60e1d9996c Fix Language::parseFormattedNumber for lzh and zh-classical
When parsing, filter any array values that are empty string
before using strtr php function so that strtr can handle
the array.

Bug: 64347
Change-Id: I94761caa70d44febfa0999c91048a01044fc1fbe
2014-04-25 08:52:54 +02:00
Siebrand Mazeland
69ec133bc5 Pass phpcs-strict on some test files (10/11)
Change-Id: I5624292143fcabe890779f5095eae735d7afb176
2014-04-24 13:50:56 -07:00
umherirrender
87fe91344e Remove # from dataProvider
Change-Id: Ie5414173b95e846d735827bffa34c73698e48c17
2014-04-18 19:10:38 +02:00
Ladsgroup
16a5102765 Change URLs to mediawiki.org in comments to HTTPS
These are only documentation fixes
http://www.mediawiki.org --> https://www.mediawiki.org

Change-Id: I62ad42be1a3aac410cc53e98ce79389ceddd8988
2014-03-20 16:59:46 +00:00
daniel
107bd92ec7 (bug #56685) make sure commafy can deal with strings.
Localization of numeric values should operate on the values as strings,
and should handle strings representign very large numbers gracefully.

Change-Id: I95394b96f9b70deb06ab818b54e08ac4ccb38c6c
2013-11-26 20:40:53 +01:00
umherirrender
5dbfd5bf80 Fixed spacing
- Removed trailing spaces in comments
- Removed multiple empty lines
- Removed space after object operator

Change-Id: I9fd3256ab490c7cd2034de3fd94e6be6e6d6d8f2
2013-11-21 18:52:25 +00:00
UltrasonicNXT
87fe16c445 Prevent space before ellipsis when truncating
When truncating a string at a point where it contains a space (ie "hello
world" to 9 chars), the resultant string will have a space before the
ellipsis ("hello ..."). This is both gramatically incorrect and just looks
wrong, and is fixed by trimming the string before appending the ellipsis.

Change-Id: Iec86b17bfc8c50e4c1a96fd373861841fc57848d
2013-11-15 14:29:18 -04:00
addshore
46a17d0fc3 Cleanup /languages/* tests
This change:
 - Adds method scope
 - adds @covers tags
 - adds various @todos
 - fixes some comments

Before the changes tests ran with:
   1383 tests, 1412 assertions 10 skips
After changes the results remain the same

Change-Id: Iee57447bdb47026952ef5dcce6fed5dad0f80e52
2013-10-22 12:32:29 +02:00
Liangent
d0e3dc94c3 Add converted namespace names as aliases to avoid confusion.
Currently if the site language is zh and a user is using variant zh-tw,
namespace names from zh-hant are displayed because of the language
converter, but they're not accepted by MediaWiki as valid namespace names
by default because zh falls back to zh-hans.

For core namespaces, all converted namespace names are manually added as
$namespaceAliases in MessagesZh.php but it's not always done in extensions.
With this patch converted namespace names are automatically added as
namespace aliases when namespace aliases are loaded.

In some followup commit it makes sense to remove existing core namespace
aliases which were created for this reason.

Change-Id: I01873d9c64a9943afbb655d6203cec9ebd39fb72
2013-08-13 13:01:40 +00:00
jenkins-bot
b8f9b16b84 Merge "New function Language::getParentLanguage()." 2013-06-28 15:15:04 +00:00
Niklas Laxström
a7a693f4b0 Avoid exceptions by first checking language code validity
Bug: 49423
Change-Id: I3fd98ba08393856311a48fa40769027460c72ef9
2013-06-13 09:35:32 +00:00
Liangent
396e18a8e5 New function Language::getParentLanguage().
Change-Id: Ib2109176b7dfc7ec2d0ee827c804cf93ea83b9e5
2013-06-10 18:07:49 +00:00
Kevin Israel
d510d0c0c7 Language::convertPlural: check if matching form exists
It is possible that only explicit plural forms are specified, and
therefore, it is possible that none match. However, handling of
explicit forms came after the count( $forms ) check, so input such
as {{PLURAL:|1=}} would trigger a "PHP Notice: Undefined offset: -1".

Change-Id: I8494de8ceb9e0cfff7203c69c21f02b3731275af
Follows-Up: I50eb0c6d1c02ca936848d310de625ed1fe43d91a
2013-05-25 19:30:53 -04:00
jenkins-bot
9cd8ce5034 Merge "Add input checks for Language::sprintfDate()" 2013-04-29 08:50:08 +00:00
Siebrand Mazeland
791d0b2a98 Update code formatting
Change-Id: I16a9b42651f1cfb1a70dffbb67b7b83dfeb90d03
2013-04-26 14:21:20 +00:00