Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
26806d3
Give the translations to gutenberg as a param
Tug Feb 11, 2019
882ef91
Fix context not attached to fragment
Tug Feb 14, 2019
154d11d
Pass down the locale to gutenberg-mobile
Tug Feb 14, 2019
af7cb42
Merge remote-tracking branch 'origin/develop' into update/send-gutenb…
Tug Feb 19, 2019
ba2e6f0
Merge remote-tracking branch 'origin/develop' into update/send-gutenb…
Tug Feb 19, 2019
c575a52
Update libs/gutenberg-mobile ref
Tug Feb 19, 2019
4d5096c
Update Aztec ref and wrap translation values in an array
Tug Feb 19, 2019
4a94466
Get the locale slug from the app settings instead and support locales…
Tug Feb 19, 2019
c1bb23a
Update gutenberg-mobile ref
Tug Feb 19, 2019
013186d
Filter out non-gutenberg mobile related strings
Tug Feb 20, 2019
644579d
Log error instead of printing stacktrace
Tug Feb 20, 2019
ac433d6
Update gutenberg-mobile ref after merge from develop
Tug Feb 20, 2019
444bc1e
Load resource class from the main package using the Application class…
Tug Feb 20, 2019
90c591e
Make sure Package is not null
Tug Feb 21, 2019
dd1f1da
Update gutenberg-mobile ref
Tug Feb 21, 2019
fdf04b6
Fix spacing lint issue
Tug Feb 21, 2019
3afa68e
Fix more lint issues
Tug Feb 21, 2019
41ddfaa
Fix more lint issues
Tug Feb 21, 2019
90fcc93
Fix more lint issues
Tug Feb 21, 2019
5508ee5
Fix more lint issues
Tug Feb 21, 2019
4f4c1d1
Update gutenberg-mobile ref
Tug Feb 21, 2019
63498b1
Merge remote-tracking branch 'origin/develop' into update/send-gutenb…
Tug Feb 21, 2019
fd308ea
Update gutenberg-mobile ref
Tug Feb 21, 2019
2407b09
Add comments to getTranslations
Tug Feb 21, 2019
2b10286
Update gutenberg-mobile ref
Tug Feb 21, 2019
dc5bbce
Make sure we get the resources from the application context not from …
Tug Feb 21, 2019
d53a9f4
Merge branch 'develop' into update/send-gutenberg-translations
hypest Feb 21, 2019
067e721
Update gb-mobile hash to the merged commit
hypest Feb 21, 2019
15a9701
Trim comments just to make the method 200-lines long
hypest Feb 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,6 @@ protected void onCreate(Bundle savedInstanceState) {

// Check whether to show the visual editor
PreferenceManager.setDefaultValues(this, R.xml.account_settings, false);
// AppPrefs.setAztecEditorAvailable(true);
// AppPrefs.setAztecEditorEnabled(true);
mShowAztecEditor = AppPrefs.isAztecEditorEnabled();
mShowNewEditor = AppPrefs.isVisualEditorEnabled();

Expand Down Expand Up @@ -450,8 +448,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
newPostSetup();
} else if (extras != null) {
// Load post passed in extras
mPost = mPostStore.getPostByLocalPostId(extras.getInt(EXTRA_POST_LOCAL_ID));
mPost = mPostStore.getPostByLocalPostId(extras.getInt(EXTRA_POST_LOCAL_ID)); // Load post from extras

if (mPost != null) {
initializePostObject();
Expand All @@ -476,8 +473,7 @@ protected void onCreate(Bundle savedInstanceState) {

showDialogProgress(mIsDialogProgressShown);

// if we have a remote id saved, let's first try with that, as the local Id might have changed
// after FETCH_POSTS
// if we have a remote id saved, let's first try that, as the local Id might have changed after FETCH_POSTS
if (savedInstanceState.containsKey(STATE_KEY_POST_REMOTE_ID)) {
mPost = mPostStore.getPostByRemotePostId(savedInstanceState.getLong(STATE_KEY_POST_REMOTE_ID), mSite);
initializePostObject();
Expand Down Expand Up @@ -544,9 +540,8 @@ protected void onCreate(Bundle savedInstanceState) {
if (mIsNewPost) {
trackEditorCreatedPost(action, getIntent());
} else {
// if we are opening a Post for which an error notification exists, we need to remove
// it from the dashboard to prevent the user from tapping RETRY on a Post that is
// being currently edited
// if we are opening a Post for which an error notification exists, we need to remove it from the dashboard
// to prevent the user from tapping RETRY on a Post that is being currently edited
UploadService.cancelFinalNotification(this, mPost);
resetUploadingMediaToFailedIfPostHasNotMediaInProgressOrQueued();
}
Expand All @@ -560,9 +555,8 @@ protected void onCreate(Bundle savedInstanceState) {
mViewPager.setOffscreenPageLimit(3);
mViewPager.setPagingEnabled(false);

// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
// When swiping between different sections, select the corresponding tab. We can also use ActionBar.Tab#select()
// to do this if we have a reference to the Tab.
mViewPager.clearOnPageChangeListeners();
mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
Expand Down Expand Up @@ -2211,7 +2205,9 @@ public Fragment getItem(int position) {
if (mShowGutenbergEditor) {
// Show the GB informative dialog on editing GB posts
showGutenbergInformativeDialog();
return GutenbergEditorFragment.newInstance("", "", mIsNewPost);
String languageString = LocaleManager.getLanguage(EditPostActivity.this);
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, let's see, is there some specific reason we're using LocaleManager.getLanguage() here (which gets the device language) but we use Configuration.locale later in getTranslations() (which get's the current app locale)?

Unfortunately, the device and app locales can be out of sync unless the app is restarted so, this ends up having, for example, English UI (see top bar) but Spanish content strings (see the title placeholder):
screenshot-1550760388652

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: Locale.getLanguage(context) will only return the device language if no custom app-level language is set in SharedPreferences.

return prefs.getString(LANGUAGE_KEY, LanguageUtils.getCurrentDeviceLanguageCode());

String wpcomLocaleSlug = languageString.replace("_", "-").toLowerCase(Locale.ENGLISH);
return GutenbergEditorFragment.newInstance("", "", mIsNewPost, wpcomLocaleSlug);
} else if (mShowAztecEditor) {
return AztecEditorFragment.newInstance("", "",
AppPrefs.isAztecEditorToolbarExpanded());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ public class GutenbergContainerFragment extends Fragment {
public static final String TAG = "gutenberg_container_fragment_tag";

private static final String ARG_IS_NEW_POST = "param_is_new_post";
private static final String ARG_LOCALE = "param_locale";
private static final String ARG_TRANSLATIONS = "param_translations";

private boolean mHtmlModeEnabled;
private boolean mHasReceivedAnyContent;

private WPAndroidGlueCode mWPAndroidGlueCode;

public static GutenbergContainerFragment newInstance(boolean isNewPost) {
public static GutenbergContainerFragment newInstance(boolean isNewPost, String localeString, Bundle translations) {
GutenbergContainerFragment fragment = new GutenbergContainerFragment();
Bundle args = new Bundle();
args.putBoolean(ARG_IS_NEW_POST, isNewPost);
args.putString(ARG_LOCALE, localeString);
args.putBundle(ARG_TRANSLATIONS, translations);
fragment.setArguments(args);
return fragment;
}
Expand All @@ -44,6 +48,8 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

boolean isNewPost = getArguments() != null && getArguments().getBoolean(ARG_IS_NEW_POST);
String localeString = getArguments().getString(ARG_LOCALE);
Bundle translations = getArguments().getBundle(ARG_TRANSLATIONS);

mWPAndroidGlueCode = new WPAndroidGlueCode();
mWPAndroidGlueCode.onCreate(getContext());
Expand All @@ -53,7 +59,9 @@ public void onCreate(Bundle savedInstanceState) {
getActivity().getApplication(),
BuildConfig.DEBUG,
BuildConfig.BUILD_GUTENBERG_FROM_SOURCE,
isNewPost);
isNewPost,
localeString,
translations);

// clear the content initialization flag since a new ReactRootView has been created;
mHasReceivedAnyContent = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
Expand All @@ -16,6 +17,7 @@
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.Spanned;
import android.util.DisplayMetrics;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
Expand All @@ -41,6 +43,10 @@
import org.wordpress.mobile.WPAndroidGlue.WPAndroidGlueCode.OnMediaLibraryButtonListener;
import org.wordpress.mobile.WPAndroidGlue.WPAndroidGlueCode.OnReattachQueryListener;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -50,6 +56,7 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements
IHistoryListener {
private static final String KEY_HTML_MODE_ENABLED = "KEY_HTML_MODE_ENABLED";
private static final String ARG_IS_NEW_POST = "param_is_new_post";
private static final String ARG_LOCALE_SLUG = "param_locale_slug";

private static final int CAPTURE_PHOTO_PERMISSION_REQUEST_CODE = 101;

Expand All @@ -72,12 +79,14 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements

public static GutenbergEditorFragment newInstance(String title,
String content,
boolean isNewPost) {
boolean isNewPost,
String localeSlug) {
GutenbergEditorFragment fragment = new GutenbergEditorFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM_TITLE, title);
args.putString(ARG_PARAM_CONTENT, content);
args.putBoolean(ARG_IS_NEW_POST, isNewPost);
args.putString(ARG_LOCALE_SLUG, localeSlug);
fragment.setArguments(args);
return fragment;
}
Expand All @@ -94,17 +103,86 @@ private GutenbergContainerFragment getGutenbergContainerFragment() {
return mRetainedGutenbergContainerFragment;
}

/**
* Returns the gutenberg-mobile specific translations
*
* @return Bundle a map of "english string" => [ "current locale string" ]
*/
public Bundle getTranslations() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a local method so we should change method access signature probably to private.

Copy link
Contributor

Choose a reason for hiding this comment

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

This method name doesn't tell us enough information about what is the purpose of this method.
getTranslations() is too abstract I think ?

Bundle translations = new Bundle();
Locale defaultLocale = new Locale("en");
Copy link
Contributor

Choose a reason for hiding this comment

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

This code will always return English translation, is that idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The english locale yes, the idea is for getTranslations to return a mapping of english string => [ translated string ] so we feed it to the @wordpress/i18n lib.

Resources currentResources = getActivity().getApplicationContext().getResources();
Configuration currentConfiguration = currentResources.getConfiguration();
// if the current locale of the app is english stop here and return an empty map
if (currentConfiguration.locale.equals(defaultLocale)) {
return translations;
}

// Let's create a Resources object for the default locale (english) to get the original values for our strings
DisplayMetrics metrics = new DisplayMetrics();
Configuration defaultLocaleConfiguration = new Configuration(currentConfiguration);
defaultLocaleConfiguration.setLocale(defaultLocale);
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
Resources defaultResources = new Resources(getActivity().getAssets(), metrics, defaultLocaleConfiguration);

// Strings are only being translated in the WordPress package
// thus we need to get a reference of the R class for this package
// Here we assume the Application class is at the same level as the R class
// It will not work if this lib is used outside of WordPress-Android,
// in this case let's just return an empty map
Class<?> rString;
Package mainPackage = getActivity().getApplication().getClass().getPackage();

if (mainPackage == null) {
return translations;
}

try {
rString = getActivity().getApplication().getClassLoader().loadClass(mainPackage.getName() + ".R$string");
} catch (ClassNotFoundException ex) {
return translations;
}

for (Field stringField : rString.getDeclaredFields()) {
int resourceId;
try {
resourceId = stringField.getInt(rString);
} catch (IllegalArgumentException | IllegalAccessException iae) {
AppLog.e(T.EDITOR, iae);
continue;
}

String fieldName = stringField.getName();
// Filter out all strings that are not prefixed with `gutenberg_mobile_`
if (!fieldName.startsWith("gutenberg_mobile_")) {
continue;
}

// Add the mapping english => [ translated ] to the bundle if both string are not empty
String currentResourceString = currentResources.getString(resourceId);
String defaultResourceString = defaultResources.getString(resourceId);
if (currentResourceString.length() > 0 && defaultResourceString.length() > 0) {
translations.putStringArrayList(
defaultResourceString,
new ArrayList<>(Arrays.asList(currentResourceString))
);
}
}
return translations;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (getGutenbergContainerFragment() == null) {
boolean isNewPost = getArguments().getBoolean(ARG_IS_NEW_POST);
String localeSlug = getArguments().getString(ARG_LOCALE_SLUG);

FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
GutenbergContainerFragment gutenbergContainerFragment =
GutenbergContainerFragment.newInstance(isNewPost);
GutenbergContainerFragment.newInstance(isNewPost, localeSlug, this.getTranslations());
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need for this in this.getTranslations()so we can remove it.

gutenbergContainerFragment.setRetainInstance(true);
fragmentTransaction.add(gutenbergContainerFragment, GutenbergContainerFragment.TAG);
fragmentTransaction.commitNow();
Expand Down
2 changes: 1 addition & 1 deletion libs/gutenberg-mobile
Submodule gutenberg-mobile updated 35 files
+2 −0 .gitignore
+3 −0 __mocks__/styleMock.js
+1 −1 gutenberg
+3 −0 i18n-cache/.gitignore
+3 −0 i18n-cache/data/.gitignore
+129 −0 i18n-cache/index.js
+10 −1 ios/gutenberg/GutenbergViewController.swift
+1 −0 jest/setup.js
+7 −1 package.json
+10 −0 react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java
+56 −0 react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecPasteEvent.java
+63 −0 react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecText.java
+70 −5 react-native-aztec/ios/RNTAztecView/RCTAztecView.swift
+1 −0 react-native-aztec/ios/RNTAztecView/RCTAztecViewManager.m
+6 −0 react-native-aztec/ios/RNTAztecView/RCTAztecViewManager.swift
+7 −0 ...droid/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java
+13 −2 react-native-gutenberg-bridge/android/src/main/java/org/wordpress/mobile/WPAndroidGlue/WPAndroidGlueCode.java
+4 −0 react-native-gutenberg-bridge/index.js
+16 −2 react-native-gutenberg-bridge/ios/Gutenberg.swift
+12 −0 react-native-gutenberg-bridge/ios/GutenbergBridgeDataSource.swift
+2 −1 react-native-gutenberg-bridge/ios/RNReactNativeGutenbergBridge.swift
+52 −13 src/app/App.js
+7 −18 src/block-management/block-holder.js
+0 −16 src/block-management/block-holder.scss
+42 −17 src/block-management/block-manager.js
+19 −7 src/block-management/block-manager.scss
+50 −59 src/block-management/block-picker.js
+14 −27 src/block-management/block-picker.scss
+1 −1 src/block-management/inline-toolbar/style.scss
+0 −0 src/colors.scss
+3 −0 src/globals.js
+123 −0 src/jsdom-patches.js
+1 −0 symlinked-packages/@wordpress/dom
+1 −0 symlinked-packages/@wordpress/shortcode
+10 −3 yarn.lock