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

Feature: marker fn supports scope #132

Open
1 task done
Alegiter opened this issue Apr 27, 2022 · 11 comments
Open
1 task done

Feature: marker fn supports scope #132

Alegiter opened this issue Apr 27, 2022 · 11 comments
Labels
enhancement New feature or request PRs welcome

Comments

@Alegiter
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe

There are situations when I can't use template translation. Also I need to use translation from one scope in other place. Translation API is good than used in one place. But I need little more flex.

Describe the solution you'd like

marker(key, scope?)

or maybe
marker("scope.key") like in comment marker /** t(scope.key) */ when used in scoped component/module

Describe alternatives you've considered

No response

Describe alternatives you've considered

-

Describe alternatives you've considered

Additional context

No response

I would like to make a pull request for this feature

No

@shaharkazaz
Copy link
Collaborator

@Alegiter I'm not sure I fully understand what you mean here. can you please share an example?

@FloNeu
Copy link

FloNeu commented Aug 3, 2022

I was looking for this too... i am pretty sure he means he would like a way to use the marker function to scope the translation key and extract it into the scope-file (like marker( test1, admin ) -> creates the key in the admin-scope file)... right now when I use the marker function I can only put the keys in the top-level translation file, right? (at least I haven't found a way to do it otherwise)

@Alegiter
Copy link
Author

Alegiter commented Aug 3, 2022

@FloNeu, yes, it's exactly what I meant :)

@christophbuehler
Copy link

Any workaround to achieve this?

@FloNeu
Copy link

FloNeu commented Aug 9, 2022

Any workaround to achieve this?

Not an automatic solution as far as I have seen - I thought of generating the key-files for code into a master.json instead of the language-file directly and mark my translations with a 'prefix.'

Like when the template keys use a scope and then separate them manually. Of course, this loses some advantages of the automatic extraction - but you can later run the find-method against the master and identify missing/extra keys that way again.

But I thought it couldn't be too difficult to add this - as the extractor already looks for scope properties when taking keys from classes/templates. But I had no time to look into it yet.

What would be the best way to implement it for keys from code - as we said before an optional 2nd string property on the marker-method - or just prefixing it?

What does @shaharkazaz think on the matter - seems there is some interest in adding this feature.

@christophbuehler
Copy link

The only thing missing are the typings. marker('username', {}, 'scope') already works!

@FloNeu
Copy link

FloNeu commented Aug 16, 2022 via email

@shaharkazaz shaharkazaz added enhancement New feature or request PRs welcome labels Dec 16, 2022
@shaharkazaz
Copy link
Collaborator

@FloNeu @Alegiter You are more then welcome to open a PR for this :)

@christophbuehler
Copy link

This solution works for me without any issues.

Add this to the paths of your tsconfig:
"@ngneat/transloco-keys-manager/marker": ["tools/i18n/marker.ts"]

The contents of marker.ts:

/**
 * Custom marker for transloco-keys-manager that supports 3 parameters.
 * https://github.com/ngneat/transloco-keys-manager/issues/132
 * @param key the translation key
 * @param params this parameter is ignored, always pass void 0
 * @param lang the scope and or language
 * @returns
 */
export function marker(key: string, params?: undefined, lang?: string): string {
  return key;
}

Then use the marker like this:

import { marker } from '@ngneat/transloco-keys-manager/marker';
// ...
marker('username', void 0, 'signup');

@shaharkazaz
Copy link
Collaborator

@christophbuehler Thanks for sharing!
Anyways the signature needs to be fixed, but I think that API wise it's preferred to just support marker('scope.a') to be consistent with the comment extraction API.
What do you think?

@A77AY
Copy link

A77AY commented Jun 8, 2023

Is it possible to enable this typing? I would like to be able to pass the language / scope

I think it will be difficult to add behavior here as in the comments in the template so that the scope is taken from the directive

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

No branches or pull requests

5 participants