mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-26 11:08:13 +00:00
Locales and localization refactor with Locales as a localizer object.
Removed auto-localization from search/search_address APIs (now explicit), simplified AddressLines to subclass List[AddressLine], made display_name a computed property in Results instead of field and removed result-localization circular dependencies
This commit is contained in:
@@ -196,7 +196,6 @@ class APISearch:
|
||||
'excluded': args.exclude_place_ids,
|
||||
'viewbox': args.viewbox,
|
||||
'bounded_viewbox': args.bounded,
|
||||
'locales': _get_locales(args, api.config.DEFAULT_LANGUAGE)
|
||||
}
|
||||
|
||||
if args.query:
|
||||
@@ -213,6 +212,9 @@ class APISearch:
|
||||
except napi.UsageError as ex:
|
||||
raise UsageError(ex) from ex
|
||||
|
||||
locales = _get_locales(args, api.config.DEFAULT_LANGUAGE)
|
||||
locales.localize_results(results)
|
||||
|
||||
if args.dedupe and len(results) > 1:
|
||||
results = deduplicate_results(results, args.limit)
|
||||
|
||||
@@ -277,11 +279,14 @@ class APIReverse:
|
||||
layers=layers,
|
||||
address_details=True, # needed for display name
|
||||
geometry_output=_get_geometry_output(args),
|
||||
geometry_simplification=args.polygon_threshold,
|
||||
locales=_get_locales(args, api.config.DEFAULT_LANGUAGE))
|
||||
geometry_simplification=args.polygon_threshold)
|
||||
except napi.UsageError as ex:
|
||||
raise UsageError(ex) from ex
|
||||
|
||||
if result is not None:
|
||||
locales = _get_locales(args, api.config.DEFAULT_LANGUAGE)
|
||||
locales.localize_results([result])
|
||||
|
||||
if args.format == 'debug':
|
||||
print(loglib.get_and_disable())
|
||||
return 0
|
||||
@@ -339,11 +344,13 @@ class APILookup:
|
||||
results = api.lookup(places,
|
||||
address_details=True, # needed for display name
|
||||
geometry_output=_get_geometry_output(args),
|
||||
geometry_simplification=args.polygon_threshold or 0.0,
|
||||
locales=_get_locales(args, api.config.DEFAULT_LANGUAGE))
|
||||
geometry_simplification=args.polygon_threshold or 0.0)
|
||||
except napi.UsageError as ex:
|
||||
raise UsageError(ex) from ex
|
||||
|
||||
locales = _get_locales(args, api.config.DEFAULT_LANGUAGE)
|
||||
locales.localize_results(results)
|
||||
|
||||
if args.format == 'debug':
|
||||
print(loglib.get_and_disable())
|
||||
return 0
|
||||
@@ -425,7 +432,6 @@ class APIDetails:
|
||||
|
||||
try:
|
||||
with napi.NominatimAPI(args.project_dir) as api:
|
||||
locales = _get_locales(args, api.config.DEFAULT_LANGUAGE)
|
||||
result = api.details(place,
|
||||
address_details=args.addressdetails,
|
||||
linked_places=args.linkedplaces,
|
||||
@@ -433,19 +439,21 @@ class APIDetails:
|
||||
keywords=args.keywords,
|
||||
geometry_output=(napi.GeometryFormat.GEOJSON
|
||||
if args.polygon_geojson
|
||||
else napi.GeometryFormat.NONE),
|
||||
locales=locales)
|
||||
else napi.GeometryFormat.NONE))
|
||||
except napi.UsageError as ex:
|
||||
raise UsageError(ex) from ex
|
||||
|
||||
if result is not None:
|
||||
locales = _get_locales(args, api.config.DEFAULT_LANGUAGE)
|
||||
locales.localize_results([result])
|
||||
|
||||
if args.format == 'debug':
|
||||
print(loglib.get_and_disable())
|
||||
return 0
|
||||
|
||||
if result:
|
||||
_print_output(formatter, result, args.format or 'json',
|
||||
{'locales': locales,
|
||||
'group_hierarchy': args.group_hierarchy})
|
||||
{'group_hierarchy': args.group_hierarchy})
|
||||
return 0
|
||||
|
||||
LOG.error("Object not found in database.")
|
||||
|
||||
@@ -151,9 +151,11 @@ async def dump_results(conn: napi.SearchConnection,
|
||||
results: List[ReverseResult],
|
||||
writer: 'csv.DictWriter[str]',
|
||||
lang: Optional[str]) -> None:
|
||||
locale = napi.Locales([lang] if lang else None)
|
||||
await add_result_details(conn, results,
|
||||
LookupDetails(address_details=True, locales=locale))
|
||||
LookupDetails(address_details=True))
|
||||
|
||||
locale = napi.Locales([lang] if lang else None)
|
||||
locale.localize_results(results)
|
||||
|
||||
for result in results:
|
||||
data = {'placeid': result.place_id,
|
||||
|
||||
Reference in New Issue
Block a user