Skip to content

Commit c642d7c

Browse files
committed
support #411
1 parent bde6f25 commit c642d7c

File tree

7 files changed

+181
-16
lines changed

7 files changed

+181
-16
lines changed

NAMESPACE

+2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ export(register_software)
9797
export(register_vocabularies)
9898
export(sanitize_date)
9999
export(sanitize_str)
100+
export(set_i18n)
100101
export(set_line_separator)
102+
export(set_locales_to)
101103
export(str_to_posix)
102104
export(unload_workflow_environment)
103105
export(writeWorkflowJobDataResource)

R/geoflow_entity.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,8 @@ geoflow_entity <- R6Class("geoflow_entity",
15981598
new_thumbnail <- geoflow_relation$new()
15991599
new_thumbnail$setKey("thumbnail")
16001600
new_thumbnail$setName(layername)
1601-
new_thumbnail$setDescription(sprintf("%s - Map overview", layername))
1601+
map_overview = set_i18n(term_key = "graphic_overview", expr = "{{layername}} - {{term}}", layername = layername)
1602+
new_thumbnail$setDescription(map_overview)
16021603
thumbnail_link_template = geosapi_action$getOption("map_thumbnail_template")
16031604
thumbnail_link_template = gsub("\\{","\\{{", thumbnail_link_template)
16041605
thumbnail_link_template = gsub("\\}","\\}}", thumbnail_link_template)

R/geoflow_utils.R

+75-8
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,52 @@ get_locales_from <- function(values){
213213
return(locales)
214214
}
215215

216+
#'@name set_locales_to
217+
#'@aliases set_locales_to
218+
#'@title set_locales_to
219+
#'@description Set locales to a property values set
220+
#'
221+
#'@usage set_locales_to(values)
222+
#'
223+
#'@param values values
224+
#'
225+
#'@export
226+
set_locales_to <- function(values, locales = list()){
227+
for(lang in names(locales)){
228+
attr(values, paste0("locale#", lang)) <- locales[[lang]]
229+
}
230+
return(values)
231+
}
232+
233+
#'@name set_i18n
234+
#'@aliases set_i18n
235+
#'@title set_i18n
236+
#'@description Set default locales to a property values set
237+
#'
238+
#'@usage set_i18n(term_key, default, expr, ...)
239+
#'
240+
#'@param term_key term key
241+
#'@param default default
242+
#'@param expr expr
243+
#'@param ... named values to be passed to expr
244+
#'
245+
#'@export
246+
set_i18n <- function(term_key, default = NULL, expr = "{{term}}", ...){
247+
248+
i18n_terms = jsonlite::read_json(system.file("metadata/i18n.json", package = "geoflow"))
249+
if(!term_key %in% names(i18n_terms)) stop(sprintf("Term '%s' not defined in i18n.json file!"))
250+
locales = i18n_terms[[term_key]]
251+
252+
if(regexpr("\\{\\{term\\}\\}", expr) == -1) stop(sprintf("Expression 'expr' should at least include the key '{{term}}'"))
253+
254+
set_locales_to(
255+
values = whisker::whisker.render(expr, c(term = if(!is.null(default)) default else locales[[1]], list(...))),
256+
locales = lapply(locales, function(x){
257+
whisker::whisker.render(expr, c(term = x, list(...)))
258+
})
259+
)
260+
}
261+
216262
#' @name str_to_posix
217263
#' @aliases str_to_posix
218264
#' @title str_to_posix
@@ -814,22 +860,43 @@ describeOGCRelation <- function(entity, data_object, service, download = FALSE,
814860
out <- switch(tolower(service),
815861
"wms" = {
816862
out_wms_link = layertitle
817-
if(handle_category) out_wms_link = sprintf("%s - %s", out_wms_link, "Map access")
818-
if(handle_ogc_service_description) out_wms_link = sprintf("%s - %s", out_wms_link, "OGC Web Map Service (WMS)")
863+
if(handle_category) out_wms_link = set_i18n(
864+
term_key = "map_access",
865+
expr = {
866+
the_expr = "{{out_wms_link}} - {{term}}"
867+
if(handle_ogc_service_description) the_expr = paste0(the_expr," - OGC Web Map Service (WMS)")
868+
the_expr
869+
},
870+
out_wms_link = out_wms_link
871+
)
819872
out_wms_link
820873
},
821874
"wfs" = {
822875
out_wfs_link = layertitle
823-
if(handle_category) out_wfs_link = sprintf("%s - %s", out_wfs_link, if(download) "Data download" else "Data (features) access")
824-
if(handle_ogc_service_description) out_wfs_link = sprintf("%s - %s", out_wfs_link, "OGC Web Feature Service (WFS)")
825-
if(handle_format && !is.null(format)) out_wfs_link = sprintf("%s - %s", out_wfs_link, format)
876+
if(handle_category) out_wfs_link = set_i18n(
877+
term_key = if(download) "data_download" else "data_features_access",
878+
expr = {
879+
the_expr = "{{out_wfs_link}} - {{term}}"
880+
if(handle_ogc_service_description) the_expr = paste0(the_expr, " - OGC Web Feature Service (WFS)")
881+
if(handle_format && !is.null(format)) the_expr = paste0(the_expr, " - ", format)
882+
the_expr
883+
},
884+
out_wfs_link = out_wfs_link
885+
)
826886
out_wfs_link
827887
},
828888
"wcs" = {
829889
out_wcs_link = layertitle
830-
if(handle_category) out_wcs_link = sprintf("%s - %s", out_wcs_link, if(download) "Data download" else "Data (coverage) access")
831-
if(handle_ogc_service_description) out_wcs_link = sprintf("%s - %s", out_wcs_link, "OGC Web Coverage Service (WCS)")
832-
if(handle_format && !is.null(format)) out_wcs_link = sprintf("%s - %s", out_wcs_link, format)
890+
if(handle_category) out_wcs_link = set_i18n(
891+
term_key = if(download) "data_download" else "data_coverage_access",
892+
expr = {
893+
the_expr = "{{out_wcs_link}} - {{term}}"
894+
if(handle_ogc_service_description) the_expr = paste0(the_expr, " - OGC Web Coverage Service (WCS)")
895+
if(handle_format && !is.null(format)) the_expr = paste0(the_expr, " - ", format)
896+
the_expr
897+
},
898+
out_wcs_link = out_wcs_link
899+
)
833900
out_wcs_link
834901
}
835902
)

inst/actions/geometa_create_iso_19115.R

+8-7
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ function(action, entity, config){
348348
for(thumbnail in thumbnails){
349349
go <- ISOBrowseGraphic$new(
350350
fileName = thumbnail$link,
351-
fileDescription = thumbnail$name
351+
fileDescription = thumbnail$description
352352
)
353353
thumbnail_id = paste(tolower(entity$identifiers[["id"]]), "thumbnail", tolower(thumbnail$link),sep="_")
354354
if(include_object_identification_ids) go$setAttr("id", create_object_identification_id("browsegraphic", thumbnail_id))
@@ -807,7 +807,8 @@ function(action, entity, config){
807807
doi_or <- ISOOnlineResource$new()
808808
doi_or$setLinkage(paste0("http://dx.doi.org/", the_doi))
809809
doi_or$setName("DOI")
810-
doi_or$setDescription("Digital Object Identifier")
810+
doi_desc = set_i18n(term_key = "doi")
811+
doi_or$setDescription(doi_desc, locales = geoflow::get_locales_from(doi_desc))
811812
doi_or$setProtocol("WWW:LINK-1.0-http--link")
812813
if(include_object_identification_ids) doi_or$setAttr("id", create_object_identification_id("onlineresource", the_doi))
813814
dto$addOnlineResource(doi_or)
@@ -850,7 +851,7 @@ function(action, entity, config){
850851
name$setName(http_relation$name)
851852
}
852853
or$setName(name)
853-
or$setDescription(http_relation$description)
854+
or$setDescription(http_relation$description, locales = geoflow::get_locales_from(http_relation$description))
854855
protocol <- switch(http_relation$key,
855856
"http" = "WWW:LINK-1.0-http--link",
856857
"download" = "WWW:DOWNLOAD-1.0-http--download",
@@ -922,8 +923,8 @@ function(action, entity, config){
922923
dc_inspire1 <- ISODomainConsistency$new()
923924
cr_inspire1 <- ISOConformanceResult$new()
924925
cr_inspire_spec1 <- ISOCitation$new()
925-
cr_inspire_spec1$setTitle("Commission Regulation (EU) No 1089/2010 of 23 November 2010 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards interoperability of spatial data sets and services")
926-
cr_inspire1$setExplanation("See the referenced specification")
926+
cr_inspire_spec1$setTitle(set_i18n("inspire_spatial_data_services"))
927+
cr_inspire1$setExplanation(NA)
927928
cr_inspire_date1 <- ISODate$new()
928929
cr_inspire_date1$setDate(as.Date(ISOdate(2010,12,8)))
929930
cr_inspire_date1$setDateType("publication")
@@ -936,8 +937,8 @@ function(action, entity, config){
936937
dc_inspire2 <- ISODomainConsistency$new()
937938
cr_inspire2 <- ISOConformanceResult$new()
938939
cr_inspire_spec2 <- ISOCitation$new()
939-
cr_inspire_spec2$setTitle("COMMISSION REGULATION (EC) No 1205/2008 of 3 December 2008 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards metadata")
940-
cr_inspire2$setExplanation("See the referenced specification")
940+
cr_inspire_spec2$setTitle(set_i18n("inspire_metadata"))
941+
cr_inspire2$setExplanation(NA)
941942
cr_inspire_date2 <- ISODate$new()
942943
cr_inspire_date2$setDate(as.Date(ISOdate(2008,12,4)))
943944
cr_inspire_date2$setDateType("publication")

inst/metadata/i18n.json

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"doi": {
3+
"EN": "Digital Object Identifier",
4+
"FR": "Identifiant d'objet numérique",
5+
"ES": "Identificador de objeto digital",
6+
"AR": "معرف الكائن الرقمي",
7+
"RU": "Цифровой идентификатор объекта",
8+
"ZH": "数字对象标识符"
9+
},
10+
"graphic_overview": {
11+
"EN": "Map overview",
12+
"FR": "Aperçu de la carte",
13+
"ES": "Vista general del mapa",
14+
"AR": "نظرة عامة على الخريطة",
15+
"RU": "Обзор карты",
16+
"ZH": "地图概览"
17+
},
18+
"data_download": {
19+
"EN": "Data download",
20+
"FR": "Téléchargement de données",
21+
"ES": "Descarga de datos",
22+
"AR": "تنزيل البيانات",
23+
"RU": "Загрузка данных",
24+
"ZH": "数据下载"
25+
},
26+
"data_coverage_access": {
27+
"EN": "Data (coverage) access",
28+
"FR": "Accès aux données",
29+
"ES": "Acceso a los datos",
30+
"AR": "الوصول إلى البيانات",
31+
"RU": "Доступ к данным",
32+
"ZH": "数据访问"
33+
},
34+
"data_features_access": {
35+
"EN": "Data (features) access",
36+
"FR": "Accès aux données",
37+
"ES": "Acceso a los datos",
38+
"AR": "الوصول إلى البيانات",
39+
"RU": "Доступ к данным",
40+
"ZH": "数据访问"
41+
},
42+
"map_access": {
43+
"EN": "Map access",
44+
"FR": "Accès à la carte",
45+
"ES": "Acceso al mapa",
46+
"AR": "الوصول إلى الخريطة",
47+
"RU": "Доступ к карте",
48+
"ZH": "地图访问"
49+
},
50+
"inspire_metadata": {
51+
"EN": "Commission Regulation (EC) No 1205/2008 of 3 December 2008 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards metadata",
52+
"FR": "Règlement (CE) n o 1205/2008 de la Commission du 3 décembre 2008 portant modalités d'application de la directive 2007/2/CE du Parlement européen et du Conseil en ce qui concerne les métadonnées (Texte présentant de l'intérêt pour l'EEE)",
53+
"ES": "Reglamento (CE) n o 1205/2008 de la Comisión, de 3 de diciembre de 2008 , por el que se ejecuta la Directiva 2007/2/CE del Parlamento Europeo y del Consejo en lo que se refiere a los metadatos (Texto pertinente a efectos del EEE)"
54+
},
55+
"inspire_spatial_data_services": {
56+
"EN": "Commission Regulation (EU) No 1089/2010 of 23 November 2010 implementing Directive 2007/2/EC of the European Parliament and of the Council as regards interoperability of spatial data sets and services",
57+
"FR": "Règlement (UE) No 1089/2010 DE LA Commission du 23 novembre 2010 portant modalités d'application de la directive 2007/2/CE du Parlement européen et du Conseil en ce qui concerne l'interopérabilité des séries et des services de données géographiques",
58+
"ES": "Reglamento (UE) No 1089/2010 DE LA Comisión de 23 de noviembre de 2010 por el que se aplica la Directiva 2007/2/CE del Parlamento Europeo y del Consejo en lo que se refiere a la interoperabilidad de los conjuntos y los servicios de datos espaciales"
59+
}
60+
}

man/set_i18n.Rd

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/set_locales_to.Rd

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)