This class provides methods for evaluating the possibility of using browser-native hyphenation or initializing and using a third-party hyphenation module.
By using this API, a developer can check if browser-native hyphenation is supported for a particular language.
When browser-native hyphenation is not supported or if otherwise required, the API can be used to hyphenate texts. A third-party library "Hyphenopoly" is used in that case.
It is used internally by controls that support the wrappingType:WrappingType.Hyphenated
property.
As the class is singleton, an instance should be acquired from Hyphenation.getInstance.
wrappingType:WrappingType.Hyphenated
. This functionality is supported by sap.m.Title, sap.m.Label and sap.m.Text.
if (!Hyphenation.getInstance().canUseNativeHyphenation("en")) { Hyphenation.getInstance().initialize("en").then(function() { console.log(Hyphenation.getInstance().hyphenate("An example text to hyphenate.", "en")); }); }
For more information, see Hyphenation for Text Controls.
Caution:
Note that as the hyphenation feature uses third-party and browser-native tools, we are not responsible for any grammatical incorrectness or inconsistencies of the hyphenation. Also, the variety of supported languages is outside the scope of our control and may be subject to future changes.
Event | Description |
---|---|
error |
Fired if an error with initialization or hyphenation occurs. |
Method | Description |
---|---|
attachError |
Attaches event handler When called, the context of the event handler (its Fired if an error with initialization or hyphenation occurs. |
canUseNativeHyphenation |
Checks if native hyphenation works in the current browser for the given language. This check is performed against the value of the "lang" HTML attribute of the page. |
canUseThirdPartyHyphenation |
Checks if third-party hyphenation works for the given language. |
detachError |
Detaches event handler The passed function and listener object must match the ones used for event registration. |
sap.ui.core.hyphenation.Hyphenation.extend |
Creates a new subclass of class sap.ui.core.hyphenation.Hyphenation with name
|
fireError |
Fires event error to attached listeners. |
getInitializedLanguages |
What languages were initialized with Hyphenation#initialize |
sap.ui.core.hyphenation.Hyphenation.getInstance |
Returns the singleton instance of the Hyphenation API.
|
sap.ui.core.hyphenation.Hyphenation.getMetadata |
Returns a metadata object for class sap.ui.core.hyphenation.Hyphenation. |
hyphenate |
Hyphenates the given text with the third-party library. Adds the soft hyphen symbol at the places where words can break. |
initialize |
Initializes the third-party library for the given language. Loads required third-party resources and language-specific resources. |
isLanguageInitialized |
Checks if the given language was initialized with Hyphenation#initialize |
isLanguageSupported |
Checks if If it is a known language, the API can be used to check browser-native and third-party support. |
Attaches event handler fnFunction
to the error event of this sap.ui.core.hyphenation.Hyphenation
.
When called, the context of the event handler (its this
) will be bound to oListener
if specified, otherwise it will be bound to this sap.ui.core.hyphenation.Hyphenation
itself.
Fired if an error with initialization or hyphenation occurs.
Param | Type | DefaultValue | Description |
---|---|---|---|
oData | object |
An application-specific payload object that will be passed to the event handler along with the event object when firing the event |
|
fnFunction | function(sap.ui.base.Event) : void |
The function to be called when the event occurs |
|
oListener | object |
Context object to call the event handler with. Defaults to this |
Checks if native hyphenation works in the current browser for the given language. This check is performed against the value of the "lang" HTML attribute of the page.
Param | Type | DefaultValue | Description |
---|---|---|---|
sLang | string | sap.ui.getCore().getConfiguration().getLocale().toString() |
For what language to check. The global application language is the default one |
Checks if third-party hyphenation works for the given language.
Param | Type | DefaultValue | Description |
---|---|---|---|
sLang | string | sap.ui.getCore().getConfiguration().getLocale().toString() |
For what language to check. The global application language is the default one. |
Detaches event handler fnFunction
from the error event of this sap.ui.core.hyphenation.Hyphenation
.
The passed function and listener object must match the ones used for event registration.
Param | Type | DefaultValue | Description |
---|---|---|---|
fnFunction | function(sap.ui.base.Event) : void |
The function to be called, when the event occurs |
|
oListener | object |
Context object on which the given function had to be called |
Creates a new subclass of class sap.ui.core.hyphenation.Hyphenation with name sClassName
and enriches it with the information contained in oClassInfo
.
oClassInfo
might contain the same kind of information as described in sap.ui.base.ManagedObject.extend.
Param | Type | DefaultValue | Description |
---|---|---|---|
sClassName | string |
Name of the class being created |
|
oClassInfo | object |
Object literal with information about the class |
|
FNMetaImpl | function |
Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class |
Fires event error to attached listeners.
Param | Type | DefaultValue | Description |
---|---|---|---|
mParameters | object |
Parameters to pass along with the event |
|
sErrorMessage | string |
The message of the error. |
Returns the singleton instance of the Hyphenation API.
References:
Returns a metadata object for class sap.ui.core.hyphenation.Hyphenation.
Hyphenates the given text with the third-party library.
Adds the soft hyphen symbol at the places where words can break.
Param | Type | DefaultValue | Description |
---|---|---|---|
sText | string |
The text to hyphenate |
|
sLang | string | sap.ui.getCore().getConfiguration().getLocale().toString() |
The language of the text. The global application language is the default one |
Initializes the third-party library for the given language.
Loads required third-party resources and language-specific resources.
Param | Type | DefaultValue | Description |
---|---|---|---|
sLang | string | sap.ui.getCore().getConfiguration().getLocale().toString() |
The language for which the third-party library should be initialized. The global application language is the default one |
Checks if the given language was initialized with Hyphenation#initialize
Param | Type | DefaultValue | Description |
---|---|---|---|
sLang | string | sap.ui.getCore().getConfiguration().getLocale().toString() |
The language to check for |
Checks if Hyphenation
API knows about the given language.
If it is a known language, the API can be used to check browser-native and third-party support.
Param | Type | DefaultValue | Description |
---|---|---|---|
sLang | string | sap.ui.getCore().getConfiguration().getLocale().toString() |
For what language to check. The global application language is the default one. |