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

Loading offline resource bundles #511

Merged
merged 87 commits into from
Apr 30, 2020

Conversation

jessiejuachon
Copy link
Contributor

No description provided.

jessiejuachon and others added 30 commits March 10, 2020 17:00
Signed-off-by: Jessie <jessiejuachon@gmail.com>
…t in order to get a 304 NOT MODIFIED http response
…g file. This means max age from server will be used. Setting VIPCfg.cacheExpiredTime to 0 disables caching.
@@ -48,6 +49,43 @@ public TranslationMessage() {
super();
}

public String getMessage(final Locale locale, final String component, final SourceOpt sourceOpt,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this method added?
Aren't we going to remove source-related things out of client SDK?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 use cases for using source messages:

  1. Source not collected yet
    I think in some products, it is acceptable to deploy the product even if source messages have just been added/updated by developers, and available neither in Singleton service (online mode) nor offline bundles. (e.g. VMC deploys every 2 weeks if I am not mistaken. It can have new source strings that are not yet in the SaaS Singleton). In this case, the source message will be displayed.
  2. isPseudo = true

That being said, only these 2 use cases use the source messages. #1 is not even applicable for on-prem products where translations have to be complete before release to production. #2 is not applicable in production.

On the other hand, there is no more source collection!
Also, the fallback mechanism (as seen in the new client workflow) uses the default locale instead of the source messages because the default locale may not be the same as the source locale. The implementation of this fallback mechanism is quite simple (about 10 lines of code in StringService.getString).

Note: I have updated the code with method comments for clarity.

if (!source.equals(cachedSrcLocaleMsg) ||
cachedSrcLocaleMsg == null || cachedSrcLocaleMsg.isEmpty()) {
return FormatUtils.format(source, sourceOpt.getLocale(), args);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to consider if isPseudo == true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question.. why do we need to fetch the actual localized message if isPseudo is true? Isn't isPseudo just to show which keys use the client library? So isn't it enough to wrap the key like @@key@@?


}
}
return FormatUtils.format(message, locale, args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to consider if adding ConstantsKeys.PSEUDOCHAR2?

src/main/java/com/vmware/vipclient/i18n/VIPCfg.java Outdated Show resolved Hide resolved
@@ -86,6 +103,10 @@ public static synchronized VIPCfg getInstance() {
}
return gcInstance;
}

public static synchronized void resetInstance() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when this function will be called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See @before in CacheServiceTest.java and OfflineModeTest.java
VipCfg is different for each test so have to reset it.
I see that for other tests, you are manually putting configurations back to original as a workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change this.

src/main/java/com/vmware/vipclient/i18n/VIPCfg.java Outdated Show resolved Hide resolved
src/main/java/com/vmware/vipclient/i18n/VIPCfg.java Outdated Show resolved Hide resolved
src/main/java/com/vmware/vipclient/i18n/VIPCfg.java Outdated Show resolved Hide resolved
Comment on lines +42 to +43
path = Paths.get(Thread.currentThread().getContextClassLoader().
getResource(path.toString()).toURI());
Copy link
Contributor

@Xiaochao8 Xiaochao8 Apr 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path should be relative to current working directory instead of Thread.currentThread().getContextClassLoader(), to make it easy to collect source.
Source collection will make use of config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this change after this PR because it is related to source collection?
Also, source collection will NOT make use of config file.

@@ -53,6 +53,7 @@ public static synchronized I18nFactory getInstance(VIPCfg cfg) {
if (factory == null) {
factory = new I18nFactory(cfg);
}
factory.setCfg(cfg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next PR

Comment on lines +426 to +430
public void addMsgOriginsQueue(DataSourceEnum dataSource) {
this.msgOriginsQueue.add(dataSource);
}

public void setMsgOriginsQueue(List<DataSourceEnum> msgOriginsQueue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this 2 methods or make them private?
They don't need to exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a standard setter. This can be useful.

Comment on lines +52 to +56
public synchronized void setCacheItem (MessageCacheItem cacheItem) {
// Do not update cacheItem if timestamp is earlier than current.
// An older timestamp comes from an old thread that was blocked.
if (cacheItem.getTimestamp() < this.timestamp)
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this logic, we should prevent querying fro server parallelly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave it if much effort.

Copy link
Contributor

@Xiaochao8 Xiaochao8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to merge, please.

@jessiejuachon jessiejuachon merged commit 6bbdad3 into vmware:g11n-java-client Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REQUIREMENT][Java Client] Add capability of loading local translation bundle
4 participants