Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Language string based on David Mudrak langstring from local_amos.

Copyright: 2020 Ferran Recio <ferran@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 177 lines (8 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

langstring:: (2 methods):
  __construct()
  fix_syntax()


Class: langstring  - X-Ref

Represents a single string

__construct(string $id, string $text = '', int $timemodified = null,int $deleted = 0, stdclass $extra = null)   X-Ref
Class constructor.

param: string $id string identifier
param: string $text string text
param: int $timemodified
param: int $deleted
param: stdclass $extra

fix_syntax(string $text, int $format = 2, ?int $from = null)   X-Ref
Given a string text, returns it being formatted properly for storing in AMOS repository.

Note: This method is taken directly from local_amos as it is highly tested and robust.
The Moodle 1.x part is keep on puspose to make it easier the copy paste from both codes.
This could change in the future when AMOS stop suporting the 1.x langstrings.

We need to know for what branch the string should be prepared due to internal changes in
format required by get_string()
- for get_string() in Moodle 1.6 - 1.9 use $format == 1
- for get_string() in Moodle 2.0 and higher use $format == 2

Typical usages of this methods:
$t = langstring::fix_syntax($t);          // sanity new translations of 2.x strings
$t = langstring::fix_syntax($t, 1);       // sanity legacy 1.x strings
$t = langstring::fix_syntax($t, 2, 1);    // convert format of 1.x strings into 2.x

Backward converting 2.x format into 1.x is not supported

param: string $text string text to be fixed
param: int $format target get_string() format version
param: int $from which format version does the text come from, defaults to the same as $format
return: string