Segments
The SDK provides methods for listing and updating segments in Lokalise Vantage projects.
List segments
Section titled “List segments”Use segments to retrieve segments belonging to a content unit:
segments = client.segments('project-id', 'content-unit-id')
segments.each do |segment| puts "#{segment.number}: #{segment.value}"endReturns a LokaliseApiNext::Collections::Vantage::Segments collection containing LokaliseApiNext::Models::Vantage::Segment objects.
You can access individual segment attributes:
segment = segments.first
puts segment.idputs segment.numberputs segment.valueputs segment.statusputs segment.last_change_sourceputs segment.content_language_idputs segment.content_unit_idputs segment.project_idputs segment.metadataputs segment.created_atputs segment.updated_atPagination
Section titled “Pagination”The segments method supports cursor-based pagination.
For example, retrieve up to 20 segments:
segments = client.segments( 'project-id', 'content-unit-id', limit: 20)To retrieve the next page, pass the cursor returned by the previous response:
if segments.more? next_page = client.segments( 'project-id', 'content-unit-id', limit: 20, after: segments.cursor )endUpdate a segment
Section titled “Update a segment”Use update_segment to change a segment’s translated value, status, or both:
segment = client.update_segment( 'project-id', 'segment-id', value: 'Updated translation', status: 'APPROVED')
puts segment.valueputs segment.statusReturns a LokaliseApiNext::Models::Vantage::Segment object.
At least one of the following parameters must be provided:
value— The new translated value.status— EitherAPPROVEDorPENDING_REVIEW.
You can also update only the status:
segment = client.update_segment( 'project-id', 'segment-id', status: 'PENDING_REVIEW')Warnings
Section titled “Warnings”The API may return warnings when updating a segment. These are available through the model’s warnings attribute:
segment.warnings.each do |warning| puts warning['code'] puts warning['details']endIf no warnings are returned, segment.warnings is an empty array.
Non-translatable content
Section titled “Non-translatable content”Segment values may contain non-translatable content (NTC) enclosed between the Unicode characters U+E101 and U+E102.
Be careful when updating these values. Modifying, moving, or removing NTC fragments may break the format of the exported file.