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

language export #1518

Open
wants to merge 349 commits into
base: bchan-master
Choose a base branch
from
Open

language export #1518

wants to merge 349 commits into from

Conversation

rotty3000
Copy link
Owner

@rotty3000 rotty3000 commented Nov 7, 2024

  • define a /messages/export resource
  • generate
  • impl
  • add service access policy
  • use language key
  • buildLang
  • rename
  • format source
  • put into the language cache

Don't forget to enable the feature flag:

feature.flag.LPD-27222=true
/*
 * This could get stashed into a lib somewhere convenient
 * (I didn't want to attach it to Liferay.Language because 
 * that's such a simple object)
 */
const fetchTranslations = async (keys) => {
    return await fetch(
        '/o/language/v1.0/messages/export?' + new URLSearchParams({
            languageId: Liferay.ThemeDisplay.getLanguageId()
        }), {
            body: JSON.stringify(keys),
            headers: {
                "Accept": "application/json",
                "Content-Type": "application/json"
            },
            method: 'POST'
        }
    ).then(
        r => r.json()
    ).then(
        r => r.items.reduce(
            (map, obj) => (map[obj.key] = obj.value, map), {}
        )
    );
};

// from here is user api...

// collect the keys somewhere in the app (maybe with tooling support)
let keys = [
    "800-by-600-pixels",
    "1024-by-768-pixels",
    "AUTHORIZATION_CODE",
    "AUTHORIZATION_CODE_PKCE",
    "AUTHORIZED_OAUTH2_SAP"
];

// lastly, early before rendering
Liferay.Language.put(await fetchTranslations(keys));

Test the api with curl:

curl http://localhost:8080/o/language/v1.0/messages/export?languageId=en_US \
  -s \
  --json '["800-by-600-pixels","1024-by-768-pixels","AUTHORIZATION_CODE","AUTHORIZATION_CODE_PKCE","AUTHORIZED_OAUTH2_SAP"]' | \
  jq 'reduce .items[] as $i ({}; .[$i.key] = $i.value)'

result should be:

{
  "800-by-600-pixels": "800 by 600 Pixels",
  "1024-by-768-pixels": "1024 by 768 Pixels",
  "AUTHORIZATION_CODE": "Authorization Code",
  "AUTHORIZATION_CODE_PKCE": "PKCE Extended Authorization Code",
  "AUTHORIZED_OAUTH2_SAP": "Service Access Policy for REST Requests Authorized by OAuth2"
}

@liferay-continuous-integration
Copy link
Collaborator

To conserve resources, the PR Tester does not automatically run for every pull.

If your code changes were already tested in another pull, reference that pull in this pull so the test results can be analyzed.

If your pull was never tested, comment "ci:test" to run the PR Tester for this pull.

@rotty3000 rotty3000 force-pushed the language-export branch 2 times, most recently from 028367d to 88afa88 Compare November 8, 2024 03:12
georgel-pop-lr and others added 27 commits November 8, 2024 07:27
… by Resizer.tsx from '@liferay/layout-js-components-web'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.