You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by GitBox <gi...@apache.org> on 2021/12/29 07:31:42 UTC

[GitHub] [wicket] martin-g commented on a change in pull request #488: Save info about Locale direction LTR/RTL to Session metadata

martin-g commented on a change in pull request #488:
URL: https://github.com/apache/wicket/pull/488#discussion_r776185647



##########
File path: wicket-core/src/main/java/org/apache/wicket/core/util/lang/LocaleUtils.java
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.core.util.lang;
+
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+import org.apache.wicket.util.lang.Args;
+
+public class LocaleUtils {

Review comment:
       IMO, this class could be inlined in Session.

##########
File path: wicket-core/src/main/java/org/apache/wicket/Session.java
##########
@@ -126,6 +127,11 @@
 	{
 		private static final long serialVersionUID = 1L;
 	};
+	/** records if pages have been unlocked for the current request */
+	public static final MetaDataKey<Boolean> IS_RTL = new MetaDataKey<>()

Review comment:
       In addition to using a field we should also add a non-final getter method. This way an application can define its own logic for deciding whether to use RTL or not.

##########
File path: wicket-core/src/main/java/org/apache/wicket/Session.java
##########
@@ -126,6 +127,11 @@
 	{
 		private static final long serialVersionUID = 1L;
 	};
+	/** records if pages have been unlocked for the current request */
+	public static final MetaDataKey<Boolean> IS_RTL = new MetaDataKey<>()

Review comment:
       My suggestion in the Wicket-Bootstrap issue to use the metadata was good if this functionality was in W-B repo, because there there is no way to add a new field.
   If we are going to add this functionality to wicket-core then we could use a normal field.

##########
File path: wicket-core/src/main/java/org/apache/wicket/core/util/lang/LocaleUtils.java
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.core.util.lang;
+
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+import org.apache.wicket.util.lang.Args;
+
+public class LocaleUtils {
+	/**
+	 * taken from BidiUtils
+	 *
+	 * A regular expression for matching right-to-left language codes. See
+	 * {@link #isRtlLanguage} for the design.
+	 */
+	private static final Pattern RtlLocalesRe = Pattern.compile("^(ar|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_](Arab|Hebr|Thaa|Nkoo|Tfng))"
+					+ "(?!.*[-_](Latn|Cyrl)($|-|_))($|-|_)");
+
+	private LocaleUtils() {
+		// utility class
+	}
+
+	/**
+	 * Check if a BCP 47 / III language code indicates an RTL language, i.e.
+	 * either: - a language code explicitly specifying one of the right-to-left
+	 * scripts, e.g. "az-Arab", or
+	 * <p>
+	 * - a language code specifying one of the languages normally written in a
+	 * right-to-left script, e.g. "fa" (Farsi), except ones explicitly
+	 * specifying Latin or Cyrillic script (which are the usual LTR
+	 * alternatives).
+	 * <p>
+	 * The list of right-to-left scripts appears in the 100-199 range in
+	 * http://www.unicode.org/iso15924/iso15924-num.html, of which Arabic and

Review comment:
       use `<a href="...">`

##########
File path: wicket-core/src/main/java/org/apache/wicket/core/util/lang/LocaleUtils.java
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.core.util.lang;
+
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+import org.apache.wicket.util.lang.Args;
+
+public class LocaleUtils {
+	/**
+	 * taken from BidiUtils
+	 *
+	 * A regular expression for matching right-to-left language codes. See
+	 * {@link #isRtlLanguage} for the design.
+	 */
+	private static final Pattern RtlLocalesRe = Pattern.compile("^(ar|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_](Arab|Hebr|Thaa|Nkoo|Tfng))"
+					+ "(?!.*[-_](Latn|Cyrl)($|-|_))($|-|_)");
+
+	private LocaleUtils() {
+		// utility class
+	}
+
+	/**
+	 * Check if a BCP 47 / III language code indicates an RTL language, i.e.
+	 * either: - a language code explicitly specifying one of the right-to-left
+	 * scripts, e.g. "az-Arab", or
+	 * <p>
+	 * - a language code specifying one of the languages normally written in a
+	 * right-to-left script, e.g. "fa" (Farsi), except ones explicitly
+	 * specifying Latin or Cyrillic script (which are the usual LTR
+	 * alternatives).
+	 * <p>
+	 * The list of right-to-left scripts appears in the 100-199 range in
+	 * http://www.unicode.org/iso15924/iso15924-num.html, of which Arabic and
+	 * Hebrew are by far the most widely used. We also recognize Thaana, N'Ko,
+	 * and Tifinagh, which also have significant modern usage. The rest (Syriac,
+	 * Samaritan, Mandaic, etc.) seem to have extremely limited or no modern
+	 * usage and are not recognized. The languages usually written in a
+	 * right-to-left script are taken as those with Suppress-Script:
+	 * Hebr|Arab|Thaa|Nkoo|Tfng in
+	 * http://www.iana.org/assignments/language-subtag-registry, as well as

Review comment:
       `<a href="...">`

##########
File path: wicket-core/src/main/java/org/apache/wicket/core/util/lang/LocaleUtils.java
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.core.util.lang;
+
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+import org.apache.wicket.util.lang.Args;
+
+public class LocaleUtils {
+	/**
+	 * taken from BidiUtils
+	 *
+	 * A regular expression for matching right-to-left language codes. See
+	 * {@link #isRtlLanguage} for the design.
+	 */
+	private static final Pattern RtlLocalesRe = Pattern.compile("^(ar|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_](Arab|Hebr|Thaa|Nkoo|Tfng))"

Review comment:
       The constant name should follow Java lang conventions, i.e. all upper-case - `RTL_LOCALES_RE`

##########
File path: wicket-core/src/main/java/org/apache/wicket/core/util/lang/LocaleUtils.java
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.core.util.lang;
+
+import java.util.Locale;
+import java.util.regex.Pattern;
+
+import org.apache.wicket.util.lang.Args;
+
+public class LocaleUtils {
+	/**
+	 * taken from BidiUtils
+	 *
+	 * A regular expression for matching right-to-left language codes. See
+	 * {@link #isRtlLanguage} for the design.
+	 */
+	private static final Pattern RtlLocalesRe = Pattern.compile("^(ar|dv|he|iw|fa|nqo|ps|sd|ug|ur|yi|.*[-_](Arab|Hebr|Thaa|Nkoo|Tfng))"
+					+ "(?!.*[-_](Latn|Cyrl)($|-|_))($|-|_)");
+
+	private LocaleUtils() {
+		// utility class
+	}
+
+	/**
+	 * Check if a BCP 47 / III language code indicates an RTL language, i.e.
+	 * either: - a language code explicitly specifying one of the right-to-left
+	 * scripts, e.g. "az-Arab", or

Review comment:
       a`r`-Arab ?!

##########
File path: wicket-core/src/main/java/org/apache/wicket/Session.java
##########
@@ -126,6 +127,11 @@
 	{
 		private static final long serialVersionUID = 1L;
 	};
+	/** records if pages have been unlocked for the current request */

Review comment:
       this javadoc is wrong. it seems to be a copy from somewhere else




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org