在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):lestrrat-p5/Data-Localize开源软件地址(OpenSource Url):https://github.com/lestrrat-p5/Data-Localize开源编程语言(OpenSource Language):Perl 72.8%开源软件介绍(OpenSource Introduction):NAMEData::Localize - Alternate Data Localization API SYNOPSIS
DESCRIPTIONData::Localize is an object oriented approach to localization, aimed to be an alternate choice for Locale::Maketext, Locale::Maketext::Lexicon, and Locale::Maketext::Simple. RATIONALEFunctionality-wise, Locale::Maketext does what it advertises to do. Here's a few reasons why you might or might not choose Data::Localize over Locale::Maketext-based localizers: Object-OrientedData::Localize is completely object-oriented. YMMV. FasterOn some my benchmarks, Data::Localize is faster than Locale::Maketext by 50~80%. (But see PERFORMANCE) Scalable For Large Amount Of LexiconsWhereas Locale::Maketext generally stores the lexicons in memory, Data::Localize allows you to store this data in alternate storage. By default Data::Localize comes with a BerkeleyDB backend. BASIC WORKINGSTRUCTUREData::Localize is a wrapper around various Data::Localize::Localizer
implementers (localizers). So if you don't specify any localizers,
Data::Localize will do... nothing (unless you specify Localizers are the objects that do the actual localization. Localizers must register themselves to the Data::Localize parent, noting which languages it can handle (which usually is determined by the presence of data files like en.po, ja.po, etc). A special language ID of '*' is used to accept fallback cases. Localizers registered to handle '*' will be tried after all other language possibilities have been exhausted. If the particular localizer cannot deal with the requested string, then it simply returns nothing. AUTO-GENERATING LEXICONSLocale::Maketext allows you to supply an "_AUTO" key in the lexicon hash, which allows you to pass a non-existing key to the localize() method, and use it as the actual lexicon, if no other applicable lexicons exists. Locale::Maketext attaches this to the lexicon hash itself, but Data::Localizer differs in that it attaches to the Data::Localizer object itself, so you don't have to place _AUTO everywhere.
UTF8All data is expected to be in decoded utf8. You must "use utf8" or decode them to Perl's internal representation for all values passed to Data::Localizer. We won't try to be smart for you. USE UTF8!
USING ALTERNATE STORAGEBy default all lexicons are stored on memory, but if you're building an app with thousands and thousands of long messages, this might not be the ideal solution. In such cases, you can change where the lexicons get stored
This would cause Data::Localize to put all the lexicon data in several BerkeleyDB files under /path/to/really/fast/device Note that this approach would buy you no gain if you use Data::Localize::Namespace, as that approach by default expects everything to be in memory. DEBUGGINGDEBUGTo enable debug tracing, either set DATA_LOCALIZE_DEBUG environment variable,
or explicitly define a function before loading Data::Localize:
METHODSadd_localizerAdds a new localizer. You may either pass a localizer object, or arguments to your localizer's constructor:
localizeLocalize the given string ID, using provided variables.
detect_languagesDetects the current set of languages to use. If used in an CGI environment, will attempt to detect the language of choice from headers. See I18N::LanguageTags::Detect for details. detect_languages_from_headerDetects the language from the given header value, or from HTTP_ACCEPT_LANGUAGES environment variable localizersReturn a arrayref of localizers add_localizer_mapUsed internally. set_localizer_mapUsed internally. find_localizersFinds a localizer by its attribute. Currently only supports isa
set_languagesIf used without any arguments, calls detect_languages() and sets the current language set to the result of detect_languages(). languagesGets the current list of languages add_fallback_languagesfallback_languagescount_localizers()Return the number of localizers available get_localizer_from_lang($lang)Get appropriate localizer for language $lang grep_localizers(\&sub)Filter localizers PERFORMANCEtl;dr: Use one that fits your needs Using explicit get_handle for every requestThis benchmark assumes that you're fetching the lexicon anew for every request. This allows you to switch languages for every request Benchmark run with Mac OS X (10.8.2) perl 5.16.1
Using cached lexicon objects for allThis benchmark assumes that you're fetching the lexicon once for a particular language, and you keep it in memory for reuse. This does NOT allow you to switch languages for every request. Benchmark run with Mac OS X (10.8.2) perl 5.16.1
TODOGettext style localization files -- Make it possible to decode them CONTRIBUTORSDave Rolsky AUTHORDaisuke Maki COPYRIGHT
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论