Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing link from resource to translated community name? #616

Closed
gravitystorm opened this issue Nov 29, 2022 · 10 comments
Closed

Missing link from resource to translated community name? #616

gravitystorm opened this issue Nov 29, 2022 · 10 comments
Labels
enhancement New feature or request

Comments

@gravitystorm
Copy link
Contributor

I'm opening this here for additional visibility, and the original issue is open over on the openstreetmap-website repository at openstreetmap/openstreetmap-website#3814

I'm unable to figure out how to get the translated name for a resource, when the translation uses fallbacks based on the resource type.

For example, given the fr-chapter resource, I can look up the fr-chapter entry in i18n/pl.yml.

pl:
  fr-chapter:
    description: Pomagamy rozwijać i ulepszać OpenStreetMap we Francji.

There is no name: there, so I then look up the translation defaults for the resource type in order to determine the fallback string - i.e. pl._defaults.osm-lc. This gives

pl:
  _defaults:
    osm-lc:
      name: '{community}'

Finally, and this is where I get stuck, I need to know which community to put in there. I mean, I personally know that it's supposed to be pl._communities.openstreetmapfrance: OpenStreetMap Francja. However, I can't find any link - either in the translations file or in any resources file - that has the mapping from fr-chapter -> openstreetmapfrance.

Any guidance would be greatly appreciated!

@1ec5
Copy link
Member

1ec5 commented Nov 29, 2022

If I’m not mistaken:

if (itemStrings.community) {
const communityID = simplify(itemStrings.community);
itemStrings.community = localizerFn(`_communities.${communityID}`);
}
"community": "OpenStreetMap France",
// remove spaces, punctuation, diacritics
// for punction see https://stackoverflow.com/a/21224179
export function simplify(str) {

@gravitystorm
Copy link
Contributor Author

Right, got you. I really didn't expect the translation key to be derived from a string value like that!

Thanks for the insight.

@gravitystorm
Copy link
Contributor Author

Oh, I should have asked before I closed this - would you contemplate changing how these lookups work? Or is there a technical reason with the translation system for keeping it like this?

I find that deriving the lookup key from a string is unexpected! Is there any reason not to have the translation lookup key explicitly within the resource?

It also means that projects that are using the osm-community-index information in a different language (e.g. over on openstreetmap-website) need to reimplement (and maintain, and follow any upstream changes to) both the simplify function and also the diacritics module, to make sure that we are matching the process to convert the string into the key. Would another option be for this conversion to be done once and explicit keys used in the resource instead?

@1ec5 1ec5 reopened this Nov 29, 2022
@1ec5
Copy link
Member

1ec5 commented Nov 29, 2022

At a glance, explicitly defining the lookup key would make sense to me, even if it would require a little more work to populate those keys. However, maybe @bhousel knows of other considerations.

@bhousel
Copy link
Member

bhousel commented Nov 29, 2022

I guess most of the context is on #30 (comment) and the comments after that one. We had wanted for a while to use default strings and some method of putting strings together to make less work for our volunteer translators.

So yeah, I'm ok with changing it so that we store the generated communityID with the resource, then consumers don't need to generate it at runtime.

@1ec5 1ec5 added the enhancement New feature or request label Nov 30, 2022
@atomoil
Copy link

atomoil commented Dec 11, 2022

hey! I am up for picking this up, as I'd rather it was done in this project than re-implemented in the osm website's code. @bhousel can you give me any hints or tips on where in the code to add this, please?

@gravitystorm
Copy link
Contributor Author

I think this will depend on how the maintainers want it to be implemented, and the main choice is whether the attribute should be generated in just the output files (i.e. dist/resources.*) or also included in the source files (under resources/). For our purposes, adding the attribute only in the dist files would be fine, and it's easier to implement that way too.

I'd look at adding a communityID attribute to the code somewhere around:

if (item.strings.community) { obj.strings.community = item.strings.community; }

Of course, the maintainers might have a better approach in mind!

@bhousel
Copy link
Member

bhousel commented Dec 12, 2022

I'd look at adding a communityID attribute to the code somewhere around:

☝️ I did this..
Now the build script saves the generated communityID alongside the community string.
This new attribute is persisted in all the resources/* files, and also in the dist/resources.* files too.

@gravitystorm
Copy link
Contributor Author

@bhousel Thank you!

@atomoil
Copy link

atomoil commented Dec 14, 2022

Amazing, thank you @bhousel 🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants